0

I am trying to create a 64 by 10 matrix by efficiently multiplying two arrays.

So let's say array B has 64 elements and array C has 10 elements. I want to produce a 64 by 10 matrix from this. At the moment I am doing this

for j in range(10):
 for k in range(64):
  A[j][k] = B[k] * C[j]

but it takes relativly long for my use since I need to do this thousands of times.

Is there a way to do this really quickly and efficiently with python/numpy?

4

1 回答 1

0

Use broadcasting:

import numpy as np

b = np.array(B).reshape(64, 1)
c = np.array(C)
a =  b * c
于 2020-11-04T13:07:10.940 回答