valdezt / sigfig

A python module aimed to aid the user with visual display of scientific numbers, i.e. significant figures, rounding, spacing, etc.
12 stars 4 forks source link

Supporting Numpy arrays #8

Open freiburgermsu opened 2 years ago

freiburgermsu commented 2 years ago

Hello,

I receive this error

TypeError: Invalid input type of <class 'numpy.ndarray'>, expecting 1 of (<class 'numbers.Number'>, <class 'str'>, <class 'decimal.Decimal'>, <class 'sigfig.sigfig._Number'>, <class 'NoneType'>)

when I attempt to use sigfig with a Numpy.array. Can this data type be supported, to enable more efficient code and applications of your module?

MikeBusuttil commented 2 years ago

Hey @freiburgermsu , sigfig doesn't currently support iterable datatypes as input. If you'd like to submit that as a feature request, give some examples of input with their expected output and we'll take a look.

freiburgermsu commented 2 years ago

Hello @MikeBusuttil ,

Here is an example of the functionality, which I tried to run previously:

sigfig_array = sigfig.round(array(list_of_numbers), 4),
sigfig_array2 = sigfig.round(array(list_of_numbers2), 3)

where sigfig_array and sigfig_array2 would be arrays with each element of list_of_numbers and list_of_numbers2 possessing 4 and 3 significant figures, respectively.

MikeBusuttil commented 2 years ago

Ah, I see. If we get more requests for this feature we'll definitely consider adding it in a future release. In the meantime I'd recommend:

sigfig.array = [sigfig.round(n, 4) for n in array(list_of_numbers)]
sigfig.array2 = [sigfig.round(n, 3) for n in array(list_of_numbers2)]