np.where returns tuple instead of array
See original GitHub issueContradictory to the documentation, np.where
returns a tupel with the new array instead of only the array.
Reproducing code example:
import numpy as np
a = np.arange(10)
np.where(a < 5)
# (array([0, 1, 2, 3, 4]),)
Numpy/Python version information:
1.17.2 3.7.4 and also 1.18.4 3.7.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
What is the purpose of numpy.where returning a tuple?
numpy.where returns a tuple because each element of the tuple refers to a dimension. Consider this example in 2 dimensions: a = np.array([[1 ......
Read more >How to Use numpy.where() in Python with Examples
Now let's specify the true and false values. When we do this np.where will return an array of values instead of a tuple...
Read more >How to convert a list and tuple into NumPy arrays?
In this article, let's discuss how to convert a list and tuple into arrays using NumPy. NumPy provides various methods to do the...
Read more >How to create an array from existing data in NumPy
The asarray() method in NumPy can be used to create an array from data that already exists in the form of lists or...
Read more >numpy.where() – Explained with examples - thisPointer
where(). Then where() returned a tuple of arrays i.e. one for each dimension. As our array was one dimension only, so it contained...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s unfortunate that
where
was built this way. The simplest mental model is “never usewhere(arr)
, always usenonzero(arr)
”. If you follow that rule, no one reading your codebase has to work out what these docs mean in the first place!I’m going to close this due to inactivity - PRs with proposed wording improvements are of course still welcome!