pythonarraysnumpyaverage

How to convert a list of strings into a numeric numpy array?


I want to be able to calculate the mean, min and max of A:

 import numpy as np

 A = ['33.33', '33.33', '33.33', '33.37']

 NA = np.asarray(A)

 AVG = np.mean(NA, axis=0)

 print AVG

This does not work, unless converted to:

A = [33.33, 33.33, 33.33, 33.37]

Is it possible to perform this conversion automatically?


Solution

  • you want astype

    NA = NA.astype(float)