
In python, if na is a numarray:
na array([[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]])
I can type
nb = na[:,:4] nb array([[0, 1, 0, 1], [1, 0, 1, 0]])
nb[0][0]=17
na array([[17, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]])
nb and na share data. How do you write nb = na[:,:4] in a C extension module? Thanks, Daniel Holth

On Thu, 2004-01-29 at 23:12, Daniel Holth wrote:
In python, if na is a numarray:
na array([[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]])
I can type
nb = na[:,:4] nb array([[0, 1, 0, 1], [1, 0, 1, 0]])
nb[0][0]=17
na array([[17, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], [ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]])
nb and na share data.
How do you write nb = na[:,:4] in a C extension module?
Here's the quick and dirty way: nb = (PyArrayObject *) PyObject_CallMethod(na, "view", NULL); if (na->dimensions[1] >= 4) nb->dimensions[1] = 4; Todd
Thanks,
Daniel Holth
------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
-- Todd Miller Space Telescope Science Institute 3700 San Martin Drive Baltimore MD, 21030 (410) 338 - 4576
participants (2)
-
Daniel Holth
-
Todd Miller