0

I am following a python tutorial referred here (https://www.coursera.org/lecture/ai/autoencoder-understanding-word2vec-SsBB4)

In this tutorial this block of code is successfully executed:

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

But when I try to execute the same block of code

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

I don't understand whether this " <> " is a symbol ever used in 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

expected result for the code should be (38,2)

  • 1
    `<>` doesn't exist [in Python 3.x](https://docs.python.org/3.0/whatsnew/3.0.html#removed-syntax), only `!=`. I'd recommend a more up-to-date tutorial. – jonrsharpe Jun 05 '19 at 13:04
  • 1
    Python 2 or Python 3? `<>` has been removed from Python 3, use `!=` instead – Ocaso Protal Jun 05 '19 at 13:04
  • 1
    Apparently that course is tailored to Python 2. Either use the appropriate Python version, or look for a more up to date course. – deceze Jun 05 '19 at 13:05
  • 1
    Alternatively, put `from __future__ import barry_as_FLUFL` at the top of your file. – L3viathan Jun 05 '19 at 13:16

0 Answers0