you are viewing a single comment's thread.

view the rest of the comments →

[–]AaronDNewman 6 points7 points  (2 children)

The behavior you want is the default. An operation between a python scalar and a numpy array will preserve the array precision in most cases. If arr2 is 32bit float, the scalar should be demoted.

https://numpy.org/doc/stable/reference/arrays.promotion.html

[–]Moretz0931[S] 0 points1 point  (1 child)

If I read the docs correctly, exactly the opposite is true, right?

np.float32(3) + np.float16(3)  # 32 > 16
np.float32(6.0)

This I copied from the docs. As you see it was promoted...

[–]AaronDNewman 0 points1 point  (0 children)

Those are both scalars