|
Re: Confusion regarding Numeric array resizing: msg#00067python.numeric.general
On Thu, Aug 26, 2004 at 10:19:15PM -0400, Jp Calderone wrote: > > I'm confused by the restriction on resizing arrays demonstrated below: > > >>> from Numeric import array > >>> a = array([0]) > >>> a.resize((2,)) > >>> b = a > >>> a.resize((3,)) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ValueError: cannot resize an array that has been referenced or is > referencing another array in this way. Use the resize function. > >>> del b > >>> a.resize((3,)) > >>> a > array([0, 0, 0]) > > This seems like an unnecessary restriction. Is there a reason I'm > missing for it to be in place? In this case it's obvious that b is not a copy of a (because that's how Python assignment works), but if your statement was b = a[1:], it's a little different. Then, b is a view of a: a[1] = 1 will make b[0] == 1. So, the question is, how should resizing a change b? The Numeric developers decided to punt on this, I guess, and tell you to explictly make a new copy. Now, this restriction doesn't occur in numarray. Resizing an array will (maybe) make a new copy of the underlying memory. Then b in this case will no longer point to a's data, but will be the owner of the old data. [I say "maybe" as it depends on where the memory for a came from.] -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |cookedm@xxxxxxxxxxxxxxxxxxx ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Confusion regarding Numeric array resizing: 00067, Jp Calderone |
|---|---|
| Next by Date: | marker edge color: 00067, Jin-chung Hsu |
| Previous by Thread: | Confusion regarding Numeric array resizingi: 00067, Jp Calderone |
| Next by Thread: | marker edge color: 00067, Jin-chung Hsu |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |