How to use astype() In Python
We can use the .astype() function and give the argument “int”. astype() function: When we need to convert a certain array of data from one type to another, the method comes in helpful.
Parameters
- dtype: refers to data type of list, or dict of column name
- copy: boolean value,in default it’s set to True
- errors: {‘raise’, ‘ignore’}, default is ‘raise’
Python3
# code import numpy as np # an array of float values arr = np.array([ 1.5 , 2.5 , 3.5 ]) arr = arr.astype( int ) # we loop to print out range of values # at each index for i in range ( len (arr)): print ( range (arr[i])) |
Output:
range(0, 1) range(0, 2) range(0, 3)
How to Fix: ‘numpy.float64’ object cannot be interpreted as an integer
In this article, we are going to see how to fix: ‘numpy.float64’ object cannot be interpreted as an integer.
When a function or operation is applied to an object of the wrong type, a type error is raised. The ‘numpy.float64’ object cannot be interpreted as an integer is one example of this type of problem. Let’s see what we can do about that.