python将字符串数组转换为浮点数数组

方法介绍:

import numpy as np
x = np.array(['1.1', '1.2', '1.3'])
y = x.astype(np.float)

示例

n = np.array([['120', '29.9475077984', '1'], 
			['125', '31.3887667742', '1'],
			['143', '65.4147315349', '1'],
			['143', '72.3278873965', '1']])
n = n.astype(np.float)

输出:

array([[ 120. , 29.9475078 , 1. ],
[ 125. , 31.38876677, 1. ],
[ 143. , 65.41473153, 1. ],
[ 143. , 72.3278874 , 1. ]])

你可能感兴趣的:(#,numpy,利用Python进行数据分析,python,numpy,机器学习)