squeeze/expand_dims का इस्तेमाल
squeeze size-1 dimensions हटाता है और expand_dims एक वापस add करता है।
In this page:
Syntax
np.expand_dims(arr, axis)
np.squeeze(arr)
squeeze/expand_dims
expand_dims आपके चुने position पर length 1 का एक नया axis insert करता है, जो अक्सर broadcasting के लिए चाहिए। squeeze length 1 वाली axes हटाता है। आप np.newaxis से भी axes add कर सकते हैं।
Note:
arr[:, np.newaxis] एक 1-D array को एक column में बदल देता है।
उदाहरण: squeeze/expand_dims
import numpy as np
a = np.array([1, 2, 3])
col = np.expand_dims(a, axis=1)
print(col.shape)
print(a[np.newaxis, :].shape)
print(np.squeeze(col).shape)
# Output:
# (3, 1)
# (1, 3)
# (3,)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- एक ऐसी axis squeeze करना जिसकी length 1 न हो
- यह track खोना कि कौन-सी axis add हुई
- squeeze इस्तेमाल करना और unexpectedly एक ज़रूरी dimension collapse करना
चैप्टर सारांश
- expand_dims एक length-1 axis add करता है
- squeeze length-1 axes हटाता है
- np.newaxis एक shorthand है
- Broadcasting के लिए useful
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: