NumPy arrays provide a fast and efficient way to store and manipulate data in Python. They are particularly useful for representing data as vectors and matrices in machine learning. Data in NumPy arrays can be accessed directly via column and row indexes, and this is reasonably straightforward. Nevertheless, sometimes we must perform operations on arrays of data such as sum or mean of values by row or column and this requires the axis of the operation to be specified.

NumPy arrays provide a fast and efficient way to store and manipulate data in Python.

They are particularly useful for representing data as vectors and matrices in machine learning.

Data in NumPy arrays can be accessed directly via column and row indexes, and this is reasonably straightforward. Nevertheless, sometimes we must perform operations on arrays of data such as sum or mean of values by row or column and this requires the axis of the operation to be specified.

Unfortunately, the column-wise and row-wise operations on NumPy arrays do not match our intuitions gained from row and column indexing, and this can cause confusion for beginners and seasoned machine learning practitioners alike. Specifically, operations like sum can be performed **column-wise using axis=0** and **row-wise using axis=1**.

In this tutorial, you will discover how to access and operate on NumPy arrays by row and by column.

After completing this tutorial, you will know:

- How to define NumPy arrays with rows and columns of data.
- How to access values in NumPy arrays by row and column indexes.
- How to perform operations on NumPy arrays by row and column axis.

Let’s get started.

This tutorial is divided into three parts; they are:

- NumPy Array With Rows and Columns
- Rows and Columns of Data in NumPy Arrays
- NumPy Array Operations By Row and Column
- Axis=None Array-Wise Operation
- Axis=0 Column-Wise Operation
- Axis=1 Row-Wise Operation

Before we dive into the NumPy array axis, let’s refresh our knowledge of NumPy arrays.

Typically in Python, we work with lists of numbers or lists of lists of numbers. For example, we can define a two-dimensional matrix of two rows of three numbers as a list of numbers as follows:

NumPy has a separate module for linear algebra. The module contains all the functions necessary for linear algebra. numpy.linalg is the package in NumPy for NumPy Linear Algebra.

Learn numpy features to see why you should use numpy - high performance, multidimensional container, broadcasting functions, working with varied databases

Learn the uses of numpy - Alternate for lists in python, multi dimensional array, mathematical operations. See numpy applications with python libraries.

SciPy is one of the fundamental packages for scientific computations. It provides the user with mathematical algorithms and convenient built-in functions.

Learn NumPy Copy and View - Deep Copy, shallow copy and No copy in NumPy, NumPy view creation and types with examples, NumPy View vs Copy