Ruben Medrano
Ruben Medrano

Reputation: 159

New array from multiplication numpy

I have an array like this:

data=np.array(([2,4,8], [10, 20, 30], ...)) # TypeError fixed

And I want to get the result as a new array of the multiplication of each of the indices of each array:

np.array([[64], [6000], ...])

How it can be done with numpy?

Upvotes: 1

Views: 58

Answers (1)

user2357112
user2357112

Reputation: 281401

Well, that result doesn't seem to be the "multiplication of each of the indices", but here's what you seem to want:

result = data.prod(axis=1)

Example:

In [2]: data = numpy.array([[2, 4, 8], [10, 20, 30]])

In [3]: data.prod(axis=1)
Out[3]: array([  64, 6000])

See the docs for numpy.prod for more information.

Upvotes: 3

Related Questions