-2

I am learning scipy and more specifically Numpy. I wrote the following code after properly declaring an array and received the indicated error message. Would like to know why

data = np.sin(np.arange(20)).reshape(5,4)
and = data.argmax(axis=1)

Error:

File "<stdin>", line 1
and = data.argmax(axis = 1)
  ^
  SyntaxError: invalid syntax
user2357112
  • 260,549
  • 28
  • 431
  • 505
Pythonina
  • 1
  • 1
  • 1
    Oh, wait, there was actually a line break there, but because you didn't code-format your code (formatting is crucial!), your code shows up as one line and gives a very different impression of what you were trying to do. – user2357112 Apr 10 '17 at 17:13
  • I am sorry. Did not realize the question was to post this way. A new lesson learned. Thanks. – Pythonina Apr 10 '17 at 17:14
  • 1
    Don't use `and` as a variable name, it's a reserved keyword in Python – Thierry Lathuille Apr 10 '17 at 17:15

4 Answers4

2

and is a keyword in Python, used for boolean conjunction. You can't name your variables and; pick a different name.

user2357112
  • 260,549
  • 28
  • 431
  • 505
1

and is a logical operator in Python, so you cannot assign something to it.

Laurence
  • 721
  • 7
  • 24
0

You cannot use reserved words as your variables. Pick another name like and1 maybe

Silencer310
  • 862
  • 2
  • 8
  • 25
0

and is a Logical Operator use something along the sorts of _and instead