[SciPy-user] howto extract positions and values of non-zeros from array (flat)?

Samuel GARCIA sgarcia@olfac.univ-lyon1...
Thu Aug 30 08:00:07 CDT 2007


the function is where :

ind, = where(a) for 1d array
them
val = a[ind]



dmitrey a écrit :
> I have one-dimensional array with zeros and non-zeros, like
> a = array((1,0,2,3,4,0,5,0))
>
> I need to obtain positions of non-zeros and corresponding values
> ind = array((0, 2, 3,4, 6))
> val = array((1,2,3,4,5))
>
> what's the simplest way, that uses only numpy?
>
> in MATLAB it would look like [ind, val] = find(a)
>
> Regards, D.
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Samuel Garcia
Laboratoire de Neurosciences Sensorielles, Comportement, Cognition.
CNRS - UMR5020 - Universite Claude Bernard LYON 1
Equipe logistique et technique
50, avenue Tony Garnier
69366 LYON Cedex 07
FRANCE
Tél : 04 37 28 74 64
Fax : 04 37 28 76 01
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the SciPy-user mailing list