[Numpy-discussion] Addressing arrays

Zachary Pincus zachary.pincus at yale.edu
Mon Jan 30 10:50:01 EST 2012


Ted, can you clarify what you're asking for? Maybe give a trivial example of an array and the desired output?

I'm pretty sure this is a slicing question though:
> If I have a three dimensional array a=(x,y,z), can I look at the values of z given particular values for x and y?
Given that element values are scalars in this case, and indices are (x,y,z) triples, it seems likely that looking for "values of z" given an (x,y) pair is an slicing-by-index question, no?

For indexing-by-value, "fancy indexing" with boolean masks is usually the way to go... again, Ted (or Chao), if you can describe your indexing needs in a bit more detail, it's often easy to find a compact slicing and/or fancy-indexing strategy that works well and reasonably efficiently.

Zach



On Jan 30, 2012, at 10:33 AM, Chao YUE wrote:

> he is not asking for slicing. he is asking for how to index array by element value but not element index.
> 
> 2012/1/30 Zachary Pincus <zachary.pincus at yale.edu>
> a[x,y,:]
> 
> Read the slicing part of the tutorial:
> http://www.scipy.org/Tentative_NumPy_Tutorial
> (section 1.6)
> 
> And the documentation:
> http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html
> 
> 
> 
> On Jan 30, 2012, at 10:25 AM, Ted To wrote:
> 
> > Hi,
> >
> > Is there some straightforward way to access an array by values across a
> > subset of its dimensions?  For example, if I have a three dimensional
> > array a=(x,y,z), can I look at the values of z given particular values
> > for x and y?
> >
> > Thanks,
> > Ted
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> 
> 
> -- 
> ***********************************************************************************
> Chao YUE
> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
> UMR 1572 CEA-CNRS-UVSQ
> Batiment 712 - Pe 119
> 91191 GIF Sur YVETTE Cedex
> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
> ************************************************************************************
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list