简体   繁体   中英

Python: How to use functions inside numpy?

I am new to Python programming, so please bear with my nascent question.

If we want to use certain function inside numpy, say func , do we need to just import numpy once and then call the function as following:

import numpy
np.func

Or, do we further need to import specific sub modules of numpy before calling any function? Thanks.

Almost, if you want to use numpy as np you have to import it like this:

import numpy as np

Other than that you can use the functions like that.

As with every other fricking module in existence , you use the name you import it as.

import numpy
numpy.func

...

import numpy as np
np.func

If you want to use linalg you have to do:

numpy.linalg

For example, if you want to calculate determinant of x, you would do

import numpy

x = numpy.array([[1,2],[5,7]])
det_x = numpy.linalg.det(x)

#or

import numpy as np

x = np.array([[1,2],[5,7]])
det_x = np.linalg.det(x)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM