Concept Flow - Installing and importing NumPy
Start
Check if NumPy is installed
Yes / No
Import NumPy
Import NumPy
Use NumPy in code
End
This flow shows checking for NumPy, installing if missing, then importing it to use in Python.
import numpy as np arr = np.array([1, 2, 3]) print(arr)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Check if NumPy is installed | NumPy found | Proceed to import |
| 2 | Import NumPy as np | import numpy as np | NumPy module loaded as np |
| 3 | Create array with np.array([1, 2, 3]) | np.array([1, 2, 3]) | Array([1, 2, 3]) created |
| 4 | Print the array | print(arr) | [1 2 3] output to console |
| 5 | End of script | No errors | Script completes successfully |
| Variable | Start | After Step 3 | Final |
|---|---|---|---|
| np | Not defined | NumPy module | NumPy module |
| arr | Not defined | [1 2 3] | [1 2 3] |
Installing and importing NumPy: - Use 'pip install numpy' to install if missing - Import with 'import numpy as np' for easy access - Use np.array() to create arrays - Always import before using NumPy functions - Errors occur if import fails