Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a list of numbers in string format. I converted that list into numpy array using np.asarray().
np.asarray()
How do I convert the string elements to ints?
np.asarray(listx, dtype = int)
If you have x = np.matrix, where each element is '1.0' (as str) and you want to convert it to int or float:
x = np.matrix
str
int
float
x = x.astype(np.float)
Add a comment
import numpy as np nums_str = ['1','23','345'] nums_str_np = np.asarray(nums_str) nums_int_np = nums_str_np.astype('int')
nums_int_np - is now np array of integers.
nums_int_np
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
np.asarray(listx, dtype = int)? Given that the strings are integers.