First page Back Continue Last page Overview Graphics

Broadcasting

A = np.array([ [11, 12, 13],

[21, 22, 23],

[31, 32, 33] ])

B = np.array([1, 2, 3])

Result of A * B:

[[11 24 39]

[21 44 69]

[31 64 99]]

B is treated as if it were construed like this:

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

>>> B

array([[1, 2, 3],

[1, 2, 3],

[1, 2, 3]])

31

32

33

21

22

23

11

12

13

1

2

3

1

2

3

1

2

3

*

31

64

99

21

44

69

11

24

39