有人可以找出下面的代码有什么问题吗?
import numpy as np
data = np.recfromcsv("data.txt", delimiter=" ", names=['name', 'types', 'value'])
indices = np.where((data.name == 'david') * data.types.startswith('height'))
mean_value = np.mean(data.value[indices])
我想计算大卫的体重和身高的平均值并标记如下:
david>> mean(weight_2005 and weight_2012), mean (height_2005 and height_2012)
mark>> mean(weight_2005 and weight_2012), mean (height_2005 and height_2012)
从文本 (data.txt) 文件中:
david weight_2005 50
david weight_2012 60
david height_2005 150
david height_2012 160
mark weight_2005 90
mark weight_2012 85
mark height_2005 160
mark height_2012 170
我正在使用 python 3.2 和 numpy 1.8
上面的代码提供的类型错误如下:
TypeError: startswith first arg must be bytes or a tuple of bytes, not numpy.str_