[SciPy-user] Assignment of oversize values.

David Warde-Farley dwf at cs.toronto.edu
Mon Jul 20 00:30:18 EDT 2009


On 19-Jul-09, at 8:08 AM, Yosef Meller wrote:

> I expected this to raise an exception about shape error or  
> something, but it
> did not.
>
> The NumPy documentation [1] doesn't mention this case, so I just  
> wanted to ask
> if that's the intended behaveiour.

I'm pretty sure it is intended behaviour; this is perfectly consistent  
with the way sequence modification works even with normal Python lists.

In [13]: X = range(10)

In [14]: Y = range(10, 20)

In [15]: X[:5] = Y

In [16]: X
Out[16]: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5, 6, 7, 8, 9]

Similarly if you try to zip(a, b) on two things together of different  
lengths, you get back a sequence of tuples that is length min(len(a),  
len(b)) - the extras are discarded.

Regards,

David





More information about the SciPy-User mailing list