I’m new to NumPy and I’m trying to compute some simple statistics like the median or the stddev.
One of the “columns” I want to explore is a time difference (being its type the timedelta64 NumPy type), but I can’t apply those statistical ufuncs directly:
----> 1 age_request.std()
TypeError: ufunc 'divide' not supported for the input types, and the inputs could not be
safely coerced to any supported types according to the casting rule 'safe'
Why is this happening?
I know i should look into Pandas, but first I would like to familiarize myself with NumPy.
Take a look at the documentation for datetime. It lists the operations you can perform on a
timedeltaobject. Division is done like so:Be aware that this computes the floor and throws away any remainder.
As far as I know, you can only do these operations on a
timedeltaobject. Though perhaps I am wrong and you can usenumpyoperations.I would suggest converting the
timedeltaobject to microseconds and then doing your division, standard deviation, median, etc:(I should add, though, that I’m not entirely sure what the maximum integer value is that python can store and if
tdMicrosecscould exceed it.)