NumPy Getting Started
๐ NumPy โ Getting Started
NumPy is a Python library used for working with arrays, numbers, and mathematical operations. Before using NumPy, 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__ |
