Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now