Confusion regarding Numeric array resizing
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
I'm confused by the restriction on resizing arrays demonstrated below:
This seems like an unnecessary restriction. Is there a reason I'm missing for it to be in place? Jp
![](https://secure.gravatar.com/avatar/5c85708f2eed0869671a7d303ca55b85.jpg?s=120&d=mm&r=g)
On Thu, Aug 26, 2004 at 10:19:15PM -0400, Jp Calderone wrote:
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@physics.mcmaster.ca
![](https://secure.gravatar.com/avatar/5c85708f2eed0869671a7d303ca55b85.jpg?s=120&d=mm&r=g)
On Thu, Aug 26, 2004 at 10:19:15PM -0400, Jp Calderone wrote:
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@physics.mcmaster.ca
participants (2)
-
David M. Cooke
-
Jp Calderone