GalSim-developers / GalSim

The modular galaxy image simulation toolkit. Documentation:
http://galsim-developers.github.io/GalSim/
Other
227 stars 107 forks source link

horner2d returns zero-dimensional array #1074

Closed gbernstein closed 4 years ago

gbernstein commented 4 years ago

If its inputs are scalars, horner2d returns a 0-dimensional numpy array. Would it be cleaner to have this converted to a scalar?

rmjarvis commented 4 years ago

Would it? I think 0-d arrays can be used in most of the ways that a float can be used. For instance, you can do normal math with it and the result is a float

>>> x = 5
>>> a = np.empty_like(x)
>>> a
array(0)
>>> a += 5
>>> a
array(5)
>>> x = 8
>>> x += a
>>> x
13
>>> a + 5
10
>>> np.sqrt(a)
2.23606797749979
>>> math.sqrt(a)
2.23606797749979

And if you really want, you can recast it to a float easily.

>>> x = float(a)
>>> x
5.0

Is there a use case where you are having some trouble using the return value as a 0-d array?

rmjarvis commented 4 years ago

I'm assuming the lack of response here means that this isn't a problem. Feel free to reopen if you want to push back on this.