import numpy as npNumpy
Excellent summary.
Broadcasting
a = np.zeros([3,4])
aarray([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]])
rows = np.array([0,2])
vec = np.array([1,2,3]).reshape(1,-1).Ta[:,rows] += vec
aarray([[1., 0., 1., 0.],
[2., 0., 2., 0.],
[3., 0., 3., 0.]])
Indexing
a = np.arange(1, 10).reshape(3, 3)
aarray([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# An example of integer array indexing.
# The returned array will have shape (3,)
a[[0, 1, 2], [0, 1, 0]]array([1, 5, 7])
b = a[range(3), [0,2,1]]
barray([1, 6, 8])
Row to Column
b[:, np.newaxis]array([[1],
[6],
[8]])
b[..., None]array([[1],
[6],
[8]])