我试图找到v的索引,但它总是给我:
function table(name, row, key, val, entrylist){
var result;
if (table.data == undefined){
table.data = new Map();
};
switch (arguments.length) {
case 1:
result = table.data.get(name);
break;
case 2:
table.data.set(name, []);
result = table.data.get(name);
break;
case 3:
result = table.data.get(name)[row].get(key);
break;
case 4:
table.data.get(name)[row].set(key, val);
result = table.data.get(name)[row].get(key);
break;
case 5:
table.data.get(name)[row] = new Map(entrylist);
result = table.data.get(name)[row];
break;
default:
result = table.data;
};
return result;
}
我试过了:
TypeError: slice indices must be integers or None or have an __index__ method. How to resolve it?
How to find the index of an array within an array。
Finding the index of an item given a list containing it in Python
他们都没有回答我的问题
'numpy.ndarray' object has no attribute 'index'
答案 0 :(得分:6)
index
是一个列表方法。这里的v
是一个numpy数组,您需要执行以下操作:v = np.random.randn(10)
print(v)
maximum = np.max(v)
minimum = np.min(v)
print(maximum, minimum)
index_of_maximum = np.where(v == maximum)
index_of_minimum = np.where(v == minimum)
v[index_of_minimum]
v[index_of_maximum]
assert(v[index_of_maximum] == v.max())
assert(v[index_of_minimum] == v.min())