NumPy Getting Started

NumPy Getting Started
NumPy is a Python library used for working with arrays, numbers, and mathematical operations. Before NumPy Getting Started, you must install and import it.
1. Installing NumPy
Using pip:
Using conda:
If NumPy is already installed, Python will recognize it during import.
2. Importing NumPy
The standard way to import NumPy is:
Using np is a shortcut so you don’t type numpy every time.
3. Creating Your First NumPy Array
Output:
4. Checking NumPy Version
5. NumPy Arrays vs Python Lists
Python list:
NumPy array:
NumPy arrays are:
- Faster
- Require less memory
- Allow vectorized arithmetic operations
Example:
Output:
(You cannot do this easily with normal Python lists.)
6. Creating Different Types of Arrays
Array of zeros
Output:
Array of ones
Output:
Generate sequence (like Python range())
Output:
Generate evenly spaced values
Output:
7. Checking Array Attributes
Summary
| Task | Example |
|---|---|
| Install NumPy | pip install numpy |
| Import NumPy | import numpy as np |
| Create array | np.array([1,2,3]) |
| Special arrays | np.zeros(), np.ones(), np.arange() |
| Check version | np.__version__ |
