How to convert 2D float numpy array to 2D int numpy array?

前端 未结 4 915
情话喂你
情话喂你 2020-12-22 18:08

How to convert real numpy array to int numpy array? Tried using map directly to array but it did not work.

4条回答
  •  生来不讨喜
    2020-12-22 18:23

    you can use np.int_:

    >>> x = np.array([[1.0, 2.3], [1.3, 2.9]])
    >>> x
    array([[ 1. ,  2.3],
           [ 1.3,  2.9]])
    >>> np.int_(x)
    array([[1, 2],
           [1, 2]])
    

提交回复
热议问题