Numpy provides us with multi-dimensional array objects which is useful for scientific computing. In numpy, rank refers to the number of dimensions of the array. The shape is a tuple of integers providing the size of the array in each dimension.
[1,2,3] is a numpy object of rank 1 and shape 3
[[1,2], [4,5], [7,8]] is a numpy object of rank 3 and shape 2.
The following provides different ways of creating numpy objects.
import numpy as np
a = np.array([1,2,3])
print(a)
print(a.shape)
b = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
print(b)
print(b.shape)
print("a[1]=", a[1])
print("b[2,3]=", b[2,3])
c = np.zeros((2,3))
print(c)
d = np.ones((2,3))
print(d)
e = np.eye(3)
print(e)
f = np.arange(20).reshape(4,5)
print(f)
print(f[1,:])
print(f[:,1])
print(f[1:3,:])
Note that in numpy, the traditional mathematical operations happen element wise and are not matrix operations like in matlab.
g = np.array([[1,2,3],[4,5,6],[7,8,9]])
h = np.array([[21,22,23],[24,25,26],[27,28,29]])
h+g
h-g
h*g
h/g
Note the difference between dot product and multiplication.
i = np.ones((3,3))
j = np.array([1,2,3])
print(i*j)
print(i.dot(j))
print(h)
print(np.sum(h))
print(np.sum(h, axis=0))
print(h.T)
For more on numpy, refer to the official numpy tutorial here