2

I want to create an array and display it's contents and append a new item however I am encountering an error:

C:\Users\Dylan Galea\Desktop\Modelling and CS>python numpy.py
Traceback (most recent call last):
  File "numpy.py", line 1, in <module>
    import numpy as np
  File "C:\Users\Dylan Galea\Desktop\Modelling and CS\numpy.py", line 2, in <module>
    x=np.array([1,2,3,4])
AttributeError: module 'numpy' has no attribute 'array'

My code is:

import numpy as np

x=np.array([1,2,3,4])
x=np.append([x,[5],0])
print(x)
Andrew Li
  • 55,805
  • 14
  • 125
  • 143
Dylan Galea
  • 115
  • 1
  • 2
  • 9

1 Answers1

4

You should not name your file numpy.

When you are doing import numpy as np your script imports itself rather than the "real" numpy module.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154