Playing with arrays


In [26]:
import numpy as np

a = np.array([1, 2, 3])
m = np.array([[1, 2, 3], [4, 5, 6]])

print(a, '\n', a*2, '\n', 2*a)
print(m, '\n', m*2, '\n', 2*m)

p = m.dot(a)
print(p)
print(a.shape, m.shape, p.shape)


[1 2 3] 
 [2 4 6] 
 [2 4 6]
[[1 2 3]
 [4 5 6]] 
 [[ 2  4  6]
 [ 8 10 12]] 
 [[ 2  4  6]
 [ 8 10 12]]
[14 32]
(3,) (2, 3) (2,)

Magic equal operator


In [27]:
np.array([1,2,3]) == np.array([1,2,3])[:,None]


Out[27]:
array([[ True, False, False],
       [False,  True, False],
       [False, False,  True]], dtype=bool)

In [ ]: