1

I have following code:

x = array([-273.0, -176.4, -79.8, 16.9, 113.5, 210.1, 306.8, 403.4, 500.0])
y = array([2.25927498e-53, 2.56028619e-03, 8.64512988e-01, 6.27456769e+00, 1.73894734e+01,
        3.29052124e+01, 5.14612316e+01, 7.20531200e+01, 9.40718450e+01])

but array() is not recognized by the IDE, so I figure the code is using some sorta method to wrap numpy.array. So I added

import numpy.array as array

on the top, and the IDE is no longer complaining about using array(). However, when I run this code, I got

ModuleNotFoundError: No module named 'numpy.array'

So how do I use array() like a buildin function?

1
  • Normally we do import numpy as np and np.array(...). array is function in the numpy module. It can be imported by name or with the *, but the np.array(...) syntax is clearer and widely used. Commented Mar 9, 2018 at 21:38

1 Answer 1

2

You should do:

from numpy import array
x = array([-273.0, -176.4, -79.8, 16.9, 113.5, 210.1, 306.8, 403.4, 500.0])

print(type(x))
#<type 'numpy.ndarray'>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.