Reputation: 57
a is a 2x2 matrix
b is a 2x1 matrix
c is a 1x2 matrix
But ... what kind of matrices d is?
import numpy as np
a= np.array([[1,2],[3,4]])
b= np.array([[1],[2]])
c= np.array([[1,2]])
d= np.array([1,2])
Upvotes: 2
Views: 2824
Reputation: 3930
The variable d
is not a matrix but a row vector.
import numpy as np
a= np.array([[1,2],[3,4]])
b= np.array([[1],[2]])
c= np.array([[1,2]])
d= np.array([1,2])
print(a.shape, b.shape, c.shape, d.shape)
print(a.ndim, b.ndim, c.ndim, d.ndim)
outputs shapes:
(2, 2) (2, 1) (1, 2) (2,)
and dimensions:
2 2 2 1
The number of brackets indicate the number of dimensions, for example:
e = np.array([[[1,2]]])
outputs shape
(1, 1, 2)
and ndim
3
(so 3 dimensional).
Upvotes: 2