2 NumPy Creating Arrays
2 NumPy Creating Arrays
Example:
import numpy as np
arr = np.array((1, 2, 3, 4, 5))
print(arr)
Dimensions in Arrays:
A dimension in arrays is one level of array depth (nested arrays).
0-D Arrays:
0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D array.
Example:
import numpy as np
arr = np.array(42)
print(arr)
1-D Arrays:
An array that has 0-D arrays as its elements is called uni-dimensional or 1-D array.
Example:
print(arr)
2-D Arrays:
An array that has 1-D arrays as its elements is called a 2-D array.
NumPy has a whole sub module dedicated towards matrix operations called numpy.mat
Example:
Create a 2-D array containing two arrays with the values 1,2,3 and 4,5,6:
import numpy as np
print(arr)
3-D arrays:
An array that has 2-D arrays (matrices) as its elements is called 3-D array.
Example:
Create a 3-D array with two 2-D arrays, both containing two arrays with the values 1,2,3 and
4,5,6:
import numpy as np
print(arr)