Home > Back-end >  Python - Convert particular columns of data to integer
Python - Convert particular columns of data to integer

Time:11-11

I have a 2d array that is stored with NumPy. Is it possible to only convert the first and second columns to integers from float?

This is my example of a 2d array.

2D array

CodePudding user response:

You can use asType() method

import numpy as np

arrayOfFloats = np.array(
    [
        [1.2, 2.2, 3.2],
        [4.3, 5.4, 6.2]
    ]
)

arrayOfFloats[0:1, 0:2] = arrayOfFloats[0:1, 0:2].astype(np.int64)

print(arrayOfFloats)
  • Related