[Numpy-discussion] Slice and assign into new NDarray...

Vince Fulco vfulco1 at gmail.com
Sat Mar 8 19:19:17 EST 2008


* This may be a dupe as gmail hotkeys sent a draft prematurely...

After scouring material and books I remain stumped with this one as a
new Numpy user-

I have an ND array with shape (10,15) and want to slice or subset(?) the data
into a new 2D array with the following criteria:

1) Separate each 5 observations along axis=0 (row) and transpose them to
the new array with shape (50,3)


Col1     Co2     Col3

Slice1 Slice2 Slice3
...
...
...

Slice1 should have the coordinates[0:5,0], Slice2[0:5,1] and so
on...I've tried initializing the target ND array with

D = NP.zeros((50,3), dtype='int') and then assigning into it with
something like:

for s in xrange(original_array.shape[0]):
	D= NP.transpose([data[s,i:i+step] for i in range(0,data.shape[1], step)])

with step = 5 but I get errors i.e. IndexError: invalid index

Also tried various combos of explicitly referencing D coordinates but
to no avail.


TIA,

Vince Fulco



More information about the NumPy-Discussion mailing list