Use .astype . >>> a = numpy.array([1, 2, 3, 4], dtype=numpy.float64) >>> a array([ 1., 2., 3., 4.]) >>> a.astype(numpy.int64) array([1, 2, ... ... <看更多>
Search
Search
Use .astype . >>> a = numpy.array([1, 2, 3, 4], dtype=numpy.float64) >>> a array([ 1., 2., 3., 4.]) >>> a.astype(numpy.int64) array([1, 2, ... ... <看更多>
Here we've switched the contents of x from an integer to a string. ... Remember that unlike Python lists, NumPy is constrained to arrays that all contain ... ... <看更多>
For instance pandas does this conversions as expected (using numpy dtypes),. >>> pd.Series([1, np.nan], dtype=np.float64).astype(np.int) [. ... <看更多>
It is quite trivial (X=='y').astype(int). Should do the trick. It simply converts your array to True or False according to your requirements ... ... <看更多>