更新时间:2022-03-23 04:02:16
y
不能像numpy数组那样对列表进行索引.
y
which is an list cannot be indexed like numpy arrays.
示例:
y = [1,2,3,4,6]
idx = np.array([0,1])
print (y[idx]) # This will throw an error as list cannot be index this way
print (np.array(y)[idx]) # This is fine because it is a numpy array now
解决方案如果 y
是平面列表,则先将其转换为numpy
Solution
If y
is a flat list then convert it into a numpy first
y = np.array([i[1] for i in dataset]) #label for the data
如果 y
是嵌套列表,则
y = np.array([np.array(i[1]) for i in dataset]) #label for the data