Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python 'as' keyword

I don’t understand why I can’t use numpy. after I give it an alias.

I got an error for this.

import numpy as np

ar = numpy.array([1,2,3,4,5])

print(ar)

I can only type

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import numpy as np

ar = np.array([1,2,3,4,5])

print(ar)

>Solution :

That is just how the import ... as statement behaves. You choose one name for the module you are importing. If you don’t have an as clause, the module’s own name is used.

If you want to call numpy numpy, do

import numpy

if you want to call numpy np, do

import numpy as np

and if, for some bizarre reason, you want to be able to use either, do

import numpy

np = numpy
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading