在解析字符串期间,我想决定何时停止并从字符串中获取下一部分。我的主要目标是取字符串26个字符或更少字符的3个部分。在我看来,我的代码有点奇怪
data_directory = "../train-images/train-images.idx3-ubyte"
label_directory = "../train-labels/train-labels.idx1-ubyte"
data_x = npx.convert_from_file(data_directory)
labels = npx.convert_from_file(label_directory)
def dist(x1,x2):
return np.sqrt(sum(x1-x2)**2)
def knn(training_data,label,queryPoint,k=5):
vals = []
m = training_data.shape[0]
for i in range(m):
d = dist(queryPoint,training_data[i])
vals.append((d,label[i]))
vals = sorted(vals)
vals = vals[:k]
vals = np.array(vals)
new_vals = np.unique(vals[:,1],return_counts=True)
index = new_vals[1].argmax()
predict = new_vals[0][index]
return predict
pred = knn(data_x,labels,data_x[0])
print(int(pred))
答案 0 :(得分:0)
您应该可以使用Set:
var excludes = new HashSet<Char> { ' ', '-', ... };
然后使用以下命令测试您的角色是否在场景中
excludes.contains(someChar)