Thanks to visit codestin.com
Credit goes to github.com

Skip to content

np.prod returns 0 in case of integer overflow (Trac #1629) #2225

Closed
@numpy-gitbot

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1629 on 2010-10-10 by trac user kilian, assigned to unknown.

I am using np.prod to calculate the number of elements of a sparse matrix (np.prod(C.shape)) and I noticed the following behavior: In case the result is greater than 2**31, zero is returned. Instead, the result should be converted to int long int (or at least an exception should be raised).

>>> import numpy as np
>>> np.version.version
'1.4.0'
>>> np.prod([2**16,2**16])
0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions