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.

np.where returns tuple instead of array

See original GitHub issue

Contradictory 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:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Jun 1, 2020

It’s unfortunate that where was built this way. The simplest mental model is “never use where(arr), always use nonzero(arr). If you follow that rule, no one reading your codebase has to work out what these docs mean in the first place!

0reactions
rossbarcommented, Jul 11, 2020

I’m going to close this due to inactivity - PRs with proposed wording improvements are of course still welcome!

Read more comments on GitHub >

github_iconTop 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 >

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