Write a NumPy program to count the number of dimensions, number of elements and number of bytes for each element in a given array

  • برمجة بايثون

Write a NumPy program to count the number of dimensions, number of elements and number of bytes for each element in a given array.

الأجوبة

import numpy as np    
print("\nOriginal arrays:")
x = np.array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]])
print(x)
print("\nNumber of dimensions:")
print(x.ndim)
print("Number of elements:")
print(x.size)
print("Number of bytes for each element in the said array:")
print(x.itemsize) 

Sample Output:

Original arrays:
[[ 0  1  2  3  4  5  6  7  8  9 10 11]
 [12 13 14 15 16 17 18 19 20 21 22 23]]

Number of dimensions:
2
Number of elements:
24
Number of bytes for each element in the said array:
8
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...