← Back to NumPy Course | Chapter 1: Getting Started | Lesson 3 of 7

Importing NumPy

By convention everybody imports NumPy under the short name np, so code looks the same in every tutorial and project.

In this page:

  1. Importing NumPy
Syntax
python
import numpy as np

Importing NumPy

The standard import is import numpy as np. The alias np is a near-universal convention that keeps code short and readable. Once imported, every NumPy function is available as np.something.

Note: Avoid from numpy import *; it overwrites built-ins like sum, min and max.

Example: Importing NumPy

python
import numpy as np

print("NumPy version is a string:", isinstance(np.__version__, str))
print("Pi from NumPy:", np.pi)
print("Square root of 16:", np.sqrt(16))

# Output:
# NumPy version is a string: True
# Pi from NumPy: 3.141592653589793
# Square root of 16: 4.0
Related Topics
Common Mistakes
  1. Using from numpy import * and shadowing Python built-ins
  2. Using a different alias than np and confusing teammates
  3. Forgetting to import before calling np functions
Chapter Summary
  • Use import numpy as np
  • np is the universal alias
  • Avoid star imports
  • Check np.__version__ to confirm the install
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.