[SciPy-user] extracting elements of a matrix using arrays as indices
Fabrice Silva
silva@lma.cnrs-mrs...
Tue May 20 16:51:00 CDT 2008
Le mardi 20 mai 2008 à 08:03 -0600, Michael Hearne a écrit :
> In Python:
> a = array([[ 11, 12, 13, 14 ],
> [ 21, 22, 23, 24 ],
> [ 31, 32, 33, 34 ]])
> a[[0,2],[0,3]]
> gives you:
> array([11, 34])
> So, I have two questions:
> 1) How do I actually get the equivalent behavior in Python?
>>> from numpy import array
>>> a = array([[ 11, 12, 13, 14 ],
... [ 21, 22, 23, 24 ],
... [ 31, 32, 33, 34 ]])
>>> a[:,[0,3]][[0,2],:]
array([[11, 14],
[31, 34]])
>>> a[[0,2],[0,3]]
array([11, 34])
--
Fabrice Silva <silva@lma.cnrs-mrs.fr>
LMA UPR CNRS 7051 - équipe S2M
More information about the SciPy-user
mailing list