ufunc 'remainder' not supported for the input types - why modulo for numpy arrays does not work?

Viewed 2040

I have a numpy array BJD:

array(['2457217.463668', '2457217.484100', '2457217.504533', ...,
   '2457296.330660', '2457296.351092', '2457296.371524'], dtype='<U14')

I want to divide each element by period, a single number, and get the remainder. I create a numpy array again:

periodarray=np.array([period]*len(BJD))

periodarray is this then:

array(['0.5742000365944918', '0.5742000365944918', '0.5742000365944918',
   ..., '0.5742000365944918', '0.5742000365944918',
   '0.5742000365944918'], dtype='<U18')

Then to get the remainder array, I do:

remainders=np.mod(BJD,periodarray)

I get this error:

TypeError: ufunc 'remainder' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Is the problem that one array is datatype U14, the other one is U18? If yes, how can I fix it? A solution which does not fix the problem exactly but provides a simpler way of getting the remainder array is also welcomed.

0 Answers
Related