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.

Negative 2^63 when broadcasting np.inf into np.array

See original GitHub issue

numpy inf - when broadcasted into an integer Numpy Array - yields (-2 ^ 63).

Reproducing code example:

import numpy as np
mat1 = np.array([[0,1],[2,3]])
mat2 = np.array([[0.0,1.0],[2.0,3.0]])

mat1[:, 1] = np.inf
mat2[:, 1] = np.inf

out1 = np.min(mat1)
out2 = np.min(mat2)
print(out1, out2)

output on my machine: (-9223372036854775808, 0.0)

out1[0,1] is indeed -9223372036854775808

Numpy/Python version information:

1.18.1 3.7.6 (default, Jan 8 2020, 13:42:34) [Clang 4.0.1 (tags/RELEASE_401/final)]

Machine info:

Model Name: MacBook Pro Model Identifier: MacBookPro15,1 Processor Name: 8-Core Intel Core i9

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Feb 26, 2020

(int) inf is implementation-defined in C, which is where numpy gets its behavior from.

0reactions
rossbarcommented, Jul 12, 2020

Maybe a note about np.array([np.inf]).astype(int) would be useful? Suggestions welcome but if not then I think this can be closed as sufficiently answered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Broadcasting — NumPy v1.24 Manual
The term broadcasting describes how NumPy treats arrays with different shapes during arithmetic operations. Subject to certain constraints, the smaller ...
Read more >
NumPy Basics: Arrays and Vectorized Computation
Since NumPy is a large topic, I will cover many advanced NumPy features like broadcasting in more depth later (see Appendix A). For...
Read more >
Ignoring -Inf values in arrays using numpy/scipy in Python
When I take the log of negative entries, it returns -Inf, so I will have a matrix with some -Inf values as a...
Read more >
NumPy: Set whether to print full or truncated ndarray - nkmk note
When outputting a NumPy array ndarray with print(), it may be truncated if the number of elements is large.You can control whether to...
Read more >
jax.numpy package - JAX documentation - Read the Docs
Count number of occurrences of each value in array of non-negative ints. bitwise_and (x1, x2, /). Compute the bit-wise AND of two arrays...
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