Q:

Write a NumPy program to get the number of items, array dimensions, number of array dimensions and the memory size of each element of a given array

0

Write a NumPy program to get the number of items, array dimensions, number of array dimensions and the memory size of each element of 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
array_nums = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
print("Original array:")
print(array_nums)
print("\nNumber of items of the said array:")
print(array_nums.size) 
print("\nArray dimensions:")
print(array_nums.shape)
print("\nNumber of array dimensions:")
print(array_nums.ndim)
print("\nMemory size of each element of the said array")
print(array_nums.itemsize)

Sample Output:

Original array:
[[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]

Number of items of the said array:
12

Array dimensions:
(3, 4)

Number of array dimensions:
2

Memory size of each element of 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