[SciPy-user] howto extract positions and values of non-zeros from array (flat)?
Thu Aug 30 09:00:54 CDT 2007
On 8/30/07, dmitrey <email@example.com> wrote:
> 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)
There's also nonzero:
More information about the SciPy-user