question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numpy.sum() returns inconsistent types

See original GitHub issue

With 0D FieldArray inputs, numpy.sum() returns a FieldArray, as expected:

import galois
import numpy

>>> f = galois.Field(2**64-59)
>>> a = f.Random()
>>> b = f.Random()
>>> numpy.sum([a, b], axis=0)
GF(5802771140473745109, order=18446744073709551557)

However, with 1D FieldArray inputs, numpy.sum() returns a numpy.ndarray:

>>> a = f.Random((2,))
>>> b = f.Random((2,))
>>> numpy.sum([a, b], axis=0)
array([27182153923255896342, 13808647080647953998], dtype=object)

I’ve verified that numpy.add.reduce() works the same, and sum() doesn’t have a subok argument. Is this expected behavior?

Cheers, Tim

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tshead2commented, Dec 9, 2022

Yup, appreciate your help.

Cheers, Tim

0reactions
mhostettercommented, Dec 9, 2022

No problem. Is this issue good to close?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Numpy inconsistent results with Pandas and missing values
Calling np.sum on a pandas Series delegates to Series.sum , which ignores NaNs when computing the sum (BY DEFAULT). data['a'].sum() # 12.0 ...
Read more >
numpy.sum is incompatible with any of scipy.sparse matrixes
The scipy.sparse sum method could grow a dtype argument. In case it's difficult to implement the accumulator types, it could fail with ...
Read more >
numpy.sum — NumPy v1.24 Manual
The type of the returned array and of the accumulator in which the elements are summed. The dtype of a is used by...
Read more >
Writing custom array containers — NumPy v1.25.dev0 Manual
Notice that the return type is a standard numpy.ndarray . >>> type(np.multiply(arr, 2)) <class 'numpy.ndarray'>. How can we pass our custom array type...
Read more >
Writing custom array containers — NumPy v1.24 Manual
Notice that the return type is a standard numpy.ndarray . >>> type(np.multiply(arr, 2)) <class 'numpy.ndarray'>. How can we pass our custom array type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found