[Numpy-discussion] inserting indexes into an array

Tom Denniston tom.denniston at alum.dartmouth.org
Wed Sep 24 11:21:04 EDT 2008


You could try something like:

In [15]: arr = numpy.array([100,200,300])
In [16]: arr2 = numpy.empty((len(arr)*2,))
In [17]: arr2[::2]=arr
In [18]: arr2[1::2]=numpy.arange(len(arr))

In [20]: arr2
Out[20]: array([ 100.,    0.,  200.,    1.,  300.,    2.])




2008/9/24 Nadav Horesh <nadavh at visionsense.com>:
> Possibilities:
>
> column_stack((arange(len(ar)),ar))
>  or
> transpose((arange(len(ar)),ar)).ravel()
>
>   Nadav.
>
>
> -----הודעה מקורית-----
> מאת: numpy-discussion-bounces at scipy.org בשם Thomas Heller
> נשלח: ד 24-ספטמבר-08 11:30
> אל: numpy-discussion at scipy.org
> נושא: [Numpy-discussion] inserting indexes into an array
>
> I have a numpy array comtaining numbers (a, b, ...), like this:
>
> array([a, b, c, d, e, f])
>
> What is the fastest way to create another array that has the index
> of the element before each element of the original array?
>
> The result should look like this:
>
> array([0, a, 1, b, 2, c, 3, d, 4, e, 5, f])
>
> --
> Thanks,
> Thomas
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>


More information about the NumPy-Discussion mailing list