What can I do to avoid calling the numpy package every time I use it?

import numpy as np

What can I do to avoid calling the np package every time I use it?
so as not to have to write np.sum, instead just sum

I know that I can import the modules one at a time, for example:
from numpy import sum

But how can I import all numpy modules at once?

1 Like

Namespaces are usually better as it helps to avoid conflicts with builtin functions and other modules, so usually I would recommend either keeping the small namespace, or importing a number of known functions and constants that you need. But if you really want to import all of numpy, you can do this:

from numpy import *

This will import things like sum etc., but they will also overwrite builtin functions like sum.

1 Like