-1

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

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.