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/
[Python-ideas] Python array multiplication for negative values should throw an error
fjwillemsen--- via Python-ideas Tue, 31 May 2022 05:54:19 -0700
- [Python-ideas] Python array multiplication... fjwillemsen--- via Python-ideas
- [Python-ideas] Re: Python array multi... Eric Fahlgren
- [Python-ideas] Re: Python array m... Jonathan Fine
- [Python-ideas] Re: Python arr... fjwillemsen--- via Python-ideas
- [Python-ideas] Re: Python... Stephen J. Turnbull
- [Python-ideas] Re: Python array m... fjwillemsen--- via Python-ideas
- [Python-ideas] Re: Python arr... Christopher Barker
- [Python-ideas] Re: Python... Chris Angelico
- [Python-ideas] Re: Python array multi... Steven D'Aprano