![](https://secure.gravatar.com/avatar/9b85a909fbfc71a3ea3275c7872e714d.jpg?s=120&d=mm&r=g)
Hi, I have a question to Numeric/Numarray experts: Let A be a contiguous one or two-dimensional array with shape (n,) or (m,n), respectively. Let k be a positive integer less than n. Reference count for A is 1. The objective is to execute A=A[:k] or A=A[:,:k], respctively, in C. Q: Is it safe to resize the array A by simply resetting its dimensions, that is, A->dimensions[0] = k; or A->dimensions[1] = k; if A->nd is 1 or 2, respectively, in C? This appears to work but may be there are some corner cases that I have overlooked. Would that work also when using Numarray? If not, how to resize (preferably in-situ) an array in C under the conditions given above? TIA, Pearu
![](https://secure.gravatar.com/avatar/faf9400121dca9940496a7473b1d8179.jpg?s=120&d=mm&r=g)
On Mon, 2004-11-29 at 16:33, Pearu Peterson wrote:
Hi,
I have a question to Numeric/Numarray experts:
Let A be a contiguous one or two-dimensional array with shape (n,) or (m,n), respectively. Let k be a positive integer less than n. Reference count for A is 1. The objective is to execute A=A[:k] or A=A[:,:k], respctively, in C.
Q: Is it safe to resize the array A by simply resetting its dimensions, that is, A->dimensions[0] = k; or A->dimensions[1] = k;
Sounds good to me for numarray. Numeric's "dimensions" points to a C array not necessarily owned by the object... I don't know if that's a problem or not. The dimensions array storage is built into the numarray object so it's not a problem there.
if A->nd is 1 or 2, respectively, in C? This appears to work but may be there are some corner cases that I have overlooked.
Since you said 0 < k < n I think any corners are covered. It's probably good to handle m or n being 0.
Would that work also when using Numarray?
This should work unaltered in numarray. Here are a few general comments: 1. Since you're modifying in-situ, the changes are permanent unless reversed later. This is in contrast to a slice (view) which has a temporary copy of the array shape (not data) and leaves the original array unaltered. 2. Since you're not changing the size of the data, I'd call this "reshaping" and not "resizing". 3. Ref count of A is 1 eliminates any (non-data) sharing issues for numarray. Regards, Todd
participants (2)
-
Pearu Peterson
-
Todd Miller