Standard Python Library provides lists and 1d arrays (array.array)
NumPy provides multidimensional arrays (numpy.ndarray)
See, e.g.,
We can create numpy
arrays by hand, taking a list and and creating a numpy array from it:
import numpy as np
a = np.array( [-1, 0, 1] )
b = np.array( a )
print(a)
print(b)
All NumPy arrays are of type
, ndarray
type(b)
However often we want to create large array, that follow a specific sequence or of initial conditions:
Every numpy
array has attributes that describe e.g. its dimension and shape
print("Dimensions ", x.ndim)
print("Shape ", x.shape)
Many different ways to create N-dimensional arrays. A two-dimensional array or matrix can be created from, e.g., list of lists
mat = np.array( [[1,2,3], [4,5,6]] )
print(mat)
print("Dimensions: ", mat.ndim)
print("Size: ", mat.size)
print("Shape: ", mat.shape)
mat0 = np.zeros( (3,3) )
print(mat0)
mat1 = np.ones( (3,3) )
print(mat0)