1. NumPy Array Creation
NumPy’s main object is the homogeneous multidimensional array. It is a table of elements all of the same type, indexed by a tuple of non-negative integers. In NumPy dimensions are called axes.
import numpy as np # Including the Numpy package in the python
array = np.array([5, 6, 7, 8, 9]) # Creating a 1D Array
print(
array,
array.ndim, # Checking the array dimension
array.shape, # Checking the array shape
array.dtype.name, # Identiing the data type of element in numpy array
array.itemsize, # Index count starting from '0'
array.size, # Number of elements in array
type(array) ) # Identiing the numpy array type
Similarly you can check the above attributes for other dimenisons also. Below example for 0-Dimesion to n-Dimension Array are given
a3 = np.array([[1, 2, 3], [4, 5, 6]]) #2-D Arrays
a4 = np.array([ [[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]] ]) #3-D Arrays
a5 = np.array([1, 2, 3, 4], ndmin=5) #n-D Arrays
print(a1,a2,a3,a4,a5)
No comments:
Post a Comment