![](/img/trans.png)
[英]I need some help , can anybody explain the Custom sorting code below ; how exactly the code blocks are working?
[英]Need some specification on how to resolve below code?
for i in range(true_k):
print(“Cluster %d”, % i),
for ind in order_centroids[i, :10]:
print(‘ %s’ % terms[ind])
错误如下
for i in range(true_k):
print(“Cluster %d”, % i),
for ind in order_centroids[i, :10]:
print(‘ %s’ % terms[ind])
File "<ipython-input-21-459006fea4dd>", line 2
print(“Cluster %d”, % i),
^
语法错误:标识符中的字符无效
print(“Cluster %d”, % i)
应该
print(“Cluster %d” % i)
你不需要逗号。
我解决了。谢谢大家的回应,我在编码方面很新。 逗号绝对是一个错误然后我写了我的代码如下
for i in range(true_k):
print('Cluster'+ '%s' % i),
for ind in order_centroids[i, :10]:
print(' %s' % terms[ind])
所以,我有理由相信你是用 word 或其他东西编写代码,因为有巧妙的引号和糟糕的缩进。 去下载Visual Studio Code并查找如何使用它,它是一个非常流行的 IDE,将极大地帮助您进行编程。 以及键入正确类型的引号!
我相信这就是你所需要的。
for i in range(true_k):
print("Cluster {}".format(i))
for ind in order_centroids[i, :10]:
print("{}".format(terms[ind]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.