On Mon, Apr 04, 2022 at 07:46:12AM -0000, Brian McCall wrote: > Now do it for NumPy arrays
In response to Greg: [quoting Greg] I'm not convinced there's a need for new syntax here. 63*lbs 77*km/hr With appropriate definitions of lbs, km and hr these can be made to construct numbers with attached units. [end quote] Numpy arrays support array*scalar, which multiplies each element of the array by the scalar. >>> import numpy as np >>> arr = np.array([2, 3, 4, 5]) >>> arr*1.5 array([3. , 4.5, 6. , 7.5]) So we're part way there. However, I suspect that having an array of unit objects rather than low-level machine ints or floats will reduce the performance of numpy a lot. This is probably unavoidable: there is no way you can do numeric computations and track units as cheaply as doing numeric computations *without* tracking units. But performance should be the least of our concerns at this point. -- Steve _______________________________________________ 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/2ICQ7UIA27MK35W35DPVCCJ4LJEZMCK6/ Code of Conduct: http://python.org/psf/codeofconduct/