Hopefully this is not a duplicate of an existing thread or in the wrong 
section, first time posting here. 
In Python, array multiplication is quite useful to repeat an existing array, 
e.g. [1,2,3] * 2 becomes [1,2,3,4,5,6]. 
Multiplication by 0 yields an empty array: [1,2,3] * 0 becomes []. 
However, operations such as [numpy array] * -1 are very common to get the 
inverse of an array of numbers. 
The confusion here stems from the lack of type checking: while the programmer 
should check whether the array is a NumPy array or a Python array, this is not 
always done, giving rise to difficult to trace cases where [1,2,3] * -1 yields 
[] instead of [-1,-2,-3]. 
I can not think of good reasons why Python array multiplication should not 
throw an error for negative multipliers, because it is meaningless to have 
array multiplication by negative value in the way it is intended in Python. 
Instead I would propose that array multiplication by negative value throws an 
error. 
I would like to hear your opinions on this matter.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/47DZFIB46JQ55R7QFVVDDR4E2VLN2W3X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to