How do I make the following conversion in NumPy?
["1.1", "2.2", "3.2"] ⟶ [1.1, 2.2, 3.2]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, if you’re reading the data in as a list, just do
np.array(map(float, list_of_strings))(or equivalently, use a list comprehension). (In Python 3, you’ll need to callliston themapreturn value if you usemap, sincemapreturns an iterator now.)However, if it’s already a numpy array of strings, there’s a better way. Use
astype().