[Numpy-discussion] yet another indexing question
Mon Oct 17 12:13:32 CDT 2011
On 10/14/11 5:04 AM, Neal Becker wrote:
> suppose I have:
> In : u
> array([[0, 1, 2, 3, 4],
> [5, 6, 7, 8, 9]])
> And I have a vector v:
> v = np.array ((0,1,0,1,0))
> I want to form an output vector which selects items from u where v is the index
> of the row of u to be selected.
> Now, more importantly, I need the result to be a reference to the original array
> (not a copy), because I'm going to use it on the LHS of an assignment. Is this
No, it's not. numpy arrays need to be describable with regular strides
-- when selecting arbitrary elements from an array, there is no way to
describe the resulting array as regular strides into the same data block
as the original.
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
More information about the NumPy-Discussion