np.zeros/ones/full से Array बनाना
ये functions zeros, ones, या आपकी चुनी कोई value से pre-filled एक array बनाते हैं।
In this page:
Syntax
np.zeros(shape)
np.ones(shape)
np.full(shape, fill_value)
np.zeros/ones/full
np.zeros और np.ones एक दिए गए shape के arrays बनाते हैं 0 या 1 से भरे हुए, और np.full किसी भी constant से भरता है। ये placeholders और initial values के लिए ideal हैं। Multi-dimensional shapes के लिए एक tuple pass करें।
Note:
zeros और ones का default dtype float64 है; whole numbers के लिए dtype=int pass करें।
उदाहरण: np.zeros/ones/full
import numpy as np
print(np.zeros(3))
print(np.ones((2, 3), dtype=int))
print(np.full((2, 2), 7))
# Output:
# [0. 0. 0.]
# [[1 1 1]
# [1 1 1]]
# [[7 7]
# [7 7]]
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. #}
आम गलतियां
- एक shape tuple की बजाय दो numbers pass करना
- यह भूल जाना कि default dtype float है
- np.empty इस्तेमाल करना और इसकी garbage values पढ़ना
चैप्टर सारांश
- zeros, ones, और full arrays pre-fill करते हैं
- Shape एक int या tuple की तरह दी जाती है
- Default dtype float64 है
- np.full कोई भी fill value accept करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: