Python Forum
The where function in numpy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The where function in numpy
#1
Hello,

This isn't necessarily a homework problem or even about a class that I'm taking. I'm trying to teach myself python for graduate level work and I'm using a book to try and teach myself. I came across code in the book and I'm a little confused about. The code is as follows:
import Numpy as N
a = N.reshape(N.arange(8), (2,2,2) )
condition = N.logical_and(a>3, a<6)
answer_indices = N.where(condition)
answer = (a*2)[answer_indices]
Now, what I'm confused about is when you print answer_indices it comes out as:
Output:
(array([1, 1]), array([0, 0]), array([0,1]))
and I'm not entirely sure why that is. I may be a little confused with 3-D arrays in general so could somebody explain to me why this comes out this way?

Thanks.
Reply


Messages In This Thread
The where function in numpy - by saund1pe - Nov-15-2016, 04:57 PM
RE: The where function in numpy - by Larz60+ - Nov-15-2016, 05:08 PM
RE: The where function in numpy - by saund1pe - Nov-15-2016, 05:13 PM
RE: The where function in numpy - by Larz60+ - Nov-15-2016, 06:01 PM
RE: The where function in numpy - by saund1pe - Nov-16-2016, 06:44 PM
RE: The where function in numpy - by nilamo - Nov-16-2016, 08:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Need help with NumPy Histogram function coding Triikey 1 960 May-15-2023, 01:45 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020