First page Back Continue Last page Overview Graphics

Broadcasting II

31

32

33

21

22

23

11

12

13

3

3

3

2

2

2

1

1

1

*

93

96

99

42

44

46

11

12

13

Turning a row vector into a column vector:

>>> B

array([1, 2, 3])

>>> B[:, np.newaxis]

array([[1],

[2],

[3]])

>>> A * B[:, np.newaxis]

array([[11, 12, 13],

[42, 44, 46],

[93, 96, 99]])

B is treated as if it were construed like this:

>>> np.array([[1, 2, 3],] * 3).transpose()

array([[1, 1, 1],

[2, 2, 2],

[3, 3, 3]])