How to divide an array of size (a,n,m) by an array of size (a,)?

92 Views Asked by At

I have two arrays: X of size (500, 10, 10) and Y with size (500,). I need to divide each (10x10) array in X by the corresponding element in Y.

for i in range(500):
    value[i] = X[i]/Y[i]

However, I get this error: ValueError: setting an array element with a sequence.

How can I do this division?

1

There are 1 best solutions below

0
RomanPerekhrest On BEST ANSWER

Assuming that you have numpy arrays: add additional axes to Y before division:

new_arr = X / Y[:, None, None]