python中的未知运算符

时间:2019-06-05 13:02:01

标签: python

我正在关注此处(https://www.coursera.org/lecture/ai/autoencoder-understanding-word2vec-SsBB4)引用的python教程

在本教程中,以下代码块已成功执行:

https://drive.google.com/file/d/1-moHOjghmkIMiMApp6lZNjHcRpCGfwhl/view?usp=sharing

但是当我尝试执行相同的代码块

https://drive.google.com/file/d/1YUV-Fk74SESRXZ5bBmdKNvsQOLDaDlfb/view?usp=sharing

I get error   

File "<ipython-input-12-d980c3dcfd20>", line 5
    if padded_doc[i] <> 0:
                      ^
SyntaxError: invalid syntax

我不知道这个“ <>”是否是python中曾经使用过的符号。

tuples = np.empty((0,2))
for padded_doc in padded_docs:
    length = len(padded_doc)
    for i in range(length):
        if padded_doc[i] <> 0:
            if i<length-1 & padded_doc[i+1] <> 0:
                tuples = np.append(tuples, [[padded_doc[i],padded_doc[i+1]]], axis=0)
                if i<length-2 & padded_doc[i+2] <> 0:
                    tuples = np.append(tuples, [[padded_doc[i],padded_doc[i-1]]], axis = 0)
            if i>0:
                tuples = np.append(tuples, [[padded_doc[i],padded_doc[i-1]]], axis = 0)
                if i>1:
                    tuples = np.append(tuples, [[padded_doc[i],padded_doc[i-2]]], axis = 0)
print tuples.shape
tuples

该代码的预期结果应为(38,2)

0 个答案:

没有答案