why static array can be reassigned with new allocation?
rassoc
rassoc at posteo.de
Sat Oct 15 17:09:53 UTC 2022
On 10/15/22 18:20, mw via Digitalmars-d wrote:
> If you view the above two statements as in Python (numpy), it's very clear their meaning are different:
> ``` Python
> arr = other; // assign array variable to `other`
>
> arr[:] = other[:]; // assign array contents
> ```
These python arrays aren't static though.
Also, good old python will give you a view/slice of the whole array in the later case, not element-wise assignment. Numpy works differently and will fail if your shapes aren't the same:
>>> a = np.array([1,2,3])
>>> b = np.array([1,2,3,4,5])
>>> a[:] = b[:]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not broadcast input array from shape (5,) into shape (3,)
Not all that different from your initial static array example.
More information about the Digitalmars-d
mailing list