1

I am trying to find the mean of a list. I believe the negative number in the beginning of my list is somehow throwing me for a loop. Please show me the proper way to find the mean of this simple list.

B = [−5,3,12,190,−10]

print(np.mean(B))

#OUTPUT:

File "<ipython-input-35-5b44dec66063>", line 1
    B = [−5,3,12,190,−10]
          ^
SyntaxError: invalid character in identifier
Nick
  • 155
  • 2
  • 11
  • 2
    Thats not a valid negative sign. Use the key next to your 0 on your keyboard. – dfundako Sep 10 '18 at 21:57
  • 1
    [Someone else had Unicode minus sign problems just yesterday.](https://stackoverflow.com/questions/52241853/numpy-gives-nan-while-reading-a-negative-number-from-a-file) I wonder if you're working from related data sources. – user2357112 Sep 10 '18 at 22:00
  • Somehow, you managed to include an `em-dash` in your code. You need a minus sign, also known as `hyphen`. – Prune Sep 10 '18 at 22:12

2 Answers2

2

I'm assuming you maybe copy/pasted your code from somewhere. That is not a valid negative sign in Python. Use the key next to the 0 on your keyboard.

You can check to see if you are using the correct value.

Enter in this for the proper hyphen:

a = ord('-')

And this for yours:

b = ord('−')

and output them to see the difference.

dfundako
  • 8,022
  • 3
  • 18
  • 34
2

I copied and pasted part of your code into python:

c = '−5'

print(ord(c[0]))
print(ord('-'))

Gives:

8722
45
cdarke
  • 42,728
  • 8
  • 80
  • 84