The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
NumPy is Python’s core library for working with multidimensional numerical arrays. Start by installing it in the Python environment your project uses, then learn array shape, indexing, operations and broadcasting before moving on to topics such as data types, file I/O and linear algebra. This guide follows that progression and points to the official manual when you need precise API details.
What Is NumPy?
NumPy is a Python library for numerical computing. Its central object is the ndarray, a homogeneous multidimensional array: its elements use a common data type, and its values are arranged across one or more dimensions. The NumPy quickstart introduces this array model.
An array can represent a single number, a sequence, a table of values or data with more dimensions. NumPy provides tools to create arrays, select their elements and perform operations on them. For definitions and API behavior, use the NumPy v2.5 Manual.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsWhy Is NumPy Used in Python?
NumPy gives numerical data a consistent structure and lets you express operations over whole arrays instead of writing a Python loop for every element. It also provides facilities for aggregation, data conversion, random sampling, file input and output, and linear algebra. Whether a NumPy approach is faster or uses less memory than a Python list depends on the task and data; neither advantage should be assumed for every operation.
#1 Best Overall
How to Install NumPy in Python
Choose an installation method that matches how you manage the project. The official NumPy installation guide covers project-based tools such as uv and pixi, as well as environment-based workflows such as pip and conda. A virtual environment helps keep project dependencies separate.
Install with pip in a virtual environment
- Create and activate a virtual environment using the method appropriate for your operating system and Python installation.
- With that environment active, run
python -m pip install numpy. Usingpython -m pipties pip to the Python executable named bypython. - Check the installation by opening Python and running
import numpy as np, thenprint(np.__version__). The version output confirms which NumPy release that environment imports.
Conda can manage Python alongside packages and non-Python dependencies; pip installs packages for a particular Python environment. Follow the current installation instructions for your chosen tool rather than mixing package managers without a reason.
Import NumPy and Create Your First Array
The standard import convention is import numpy as np. The alias np is widely used in NumPy examples and makes calls such as np.array concise.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteimport numpy as np
values = np.array([2, 4, 6])
print(values)
print(values.ndim)
print(values.shape)
print(values.dtype)
This creates a one-dimensional array. ndim reports its number of dimensions, shape gives the size along each dimension, and dtype reports the element data type. A two-dimensional array has a shape with two entries, one for each dimension.
For a quick reference to common array-creation functions and concepts, see the manual’s quickstart and array creation guide.
Index, Slice, and Select Array Data
Indexing selects individual values; slicing selects ranges. For a two-dimensional array, separate indices with commas to address its dimensions:
matrix = np.array([[10, 20, 30],
[40, 50, 60]])
value = matrix[1, 2] # 60
first_row = matrix[0, :] # [10, 20, 30]
first_column = matrix[:, 0] # [10, 40]
Index positions start at zero. A slice such as matrix[0, :] selects every column in the first row; matrix[:, 0] selects the first column across all rows. NumPy also supports advanced indexing for selections that go beyond basic ranges. The indexing guide explains the distinctions and behaviors.
Perform Array Operations and Reductions
Arithmetic on arrays is generally element-wise when their shapes are compatible. A scalar operation applies to each element:
values = np.array([2, 4, 6])
doubled = values * 2
squared = values ** 2
Reduction functions combine values. For example, np.sum, np.mean, np.min and np.std compute a sum, mean, minimum and standard deviation. On a two-dimensional array, the axis argument controls which dimension is reduced:
Rank #4
matrix = np.array([[1, 2, 3],
[4, 5, 6]])
column_totals = np.sum(matrix, axis=0) # [5, 7, 9]
row_totals = np.sum(matrix, axis=1) # [6, 15]
Here, axis=0 reduces down the rows and leaves one result per column; axis=1 reduces across columns and leaves one result per row. Read an operation’s documentation when its axis behavior or output shape matters.
Understand Broadcasting Before Combining Shapes
Broadcasting lets NumPy perform operations on arrays with compatible shapes without requiring you to manually repeat values. A scalar can be used with an array, as in values * 2. For arrays with multiple dimensions, NumPy compares dimensions from the right: each pair must match or one of the dimensions must be 1. If the shapes are incompatible, the operation raises ValueError.
Recommended Free Tools
For example, an array shaped (2, 3) can be combined with one shaped (3,), because the trailing dimensions match. Check array.shape when an operation fails or produces an unexpected result. The official broadcasting guide details the compatibility rules.
Best Value
Progress to Intermediate and Advanced NumPy
Once array creation, indexing and shape rules are familiar, follow the branch that fits your work. The NumPy user guide organizes foundational and advanced subjects, while the reference is useful for looking up specific functions.
- Data types and conversions: Learn how an array’s
dtypeaffects its values and how to convert data when needed. See data types. - Views, copies and indexing: Understand when a selection shares underlying data and when it creates independent data. This distinction matters if you modify a result and expect the original array to remain unchanged. See copies and views.
- Array manipulation: Study reshaping and related operations when data must be reorganized. Consult the array creation and manipulation material.
- File input and output: Learn how to save arrays and load data from files using NumPy’s I/O functions. See I/O.
- Random sampling and statistics: Explore random-number generation and statistical functions for your particular problem. Begin with the random sampling reference and the statistics reference.
- Linear algebra: Use NumPy’s linear algebra functions when working with matrices and related operations. See the linear algebra reference.
- Universal functions: Learn how NumPy’s element-wise functions operate on arrays and interact with broadcasting. See universal functions.
Use Tutorials and the Manual for Different Jobs
A linked tutorial sequence is useful when you want worked examples and a learning path from installation to array fundamentals and selected advanced topics. The official manual serves a different purpose: it is the detailed reference for definitions, indexing semantics, broadcasting, data sharing, I/O and API behavior. Learn a concept with examples, then consult the relevant manual page when exact behavior matters.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

