1

sorry for rather silly question but I can't think how to do it efficiently. Say I have a matrix

a = np.arange(12).reshape(4,3)

[[ 0  1  2]
 [ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]]

How can I select the first element from each column and then multiply the whole row by it? So I want to end up with

[[ 0  1  4]
 [ 0  4  10]
 [ 0  7  16]
 [ 0 10 22]]
rami_salazar
  • 165
  • 1
  • 7

1 Answers1

0
np.array([a[0] * a for a in arr.T]).T
Alexandra Dudkina
  • 4,302
  • 3
  • 15
  • 27