0

I'm new to Python and got this code from GitHub but got an error with the @ symbol:

x=x @ self.wHidden
    ^
SyntaxError: invalid syntax

I couldn't find the solution by searching for this error.

    if self.hidden:
          x=x @ self.wHidden
          x.add_(self.wHiddenBias)
          x=x.clamp(min=0)
          x=self.dropout(x)
        x=x @ self.wNeu
        x.add_(self.wNeuBias)
skovy
  • 5,430
  • 2
  • 20
  • 34
  • what is the git url that you got this code snippet from? the `@` symbol is used to define properties or decorators in python – TheLazyScripter Sep 06 '19 at 03:48
  • what are you trying to do with this: `x=x @ self.wHidden` that is simply not valid python syntax, and I can't intuit what you were intending to do... – juanpa.arrivillaga Sep 06 '19 at 03:53

1 Answers1

1

You're using an old version of Python. The 'matmul' operator @ was introduced in Python 3.5, according to the documentation.

See the example code:

class Asdf:

    def __init__ (self, x):
        self.x = x

    def __matmul__ (self, y):
        return self.x * y

a = Asdf (5)

print (a @ 3)

It runs fine on Python3:

$ python3 ./asdf.py 
15

But it fails on Python2, with the same error as you listed above:

$ python2 ./asdf.py 
  File "./asdf.py", line 16
    print (a @ 3)
             ^
SyntaxError: invalid syntax

See this answer for details on the matmul operator.

caxcaxcoatl
  • 8,472
  • 1
  • 13
  • 21