Hello everyone, welcome back to CybercityHelp. In our previous NumPy article, we already discussed some of the basic NumPy array functions. And in today’s article, we are going to cover some specific type of NumPy array functions like one of the specific function is Matrix array function.
So we are assuming that you are already familiar with our previous NumPy array function’s article. In case if you are not aware of that article, then we suggest you to go through with that article first because they will help you understand today’s article more clearly. Here is the article link: NumPy Array Functions: What They Are and How to Use Them Properly?
So as we said, we are going to learn about NumPy Matrix function. For example, here, we will clearly understand what NumPy matrix functions are, different types of matrix functions, purpose of these matrix functions, and lastly how we can use these matrix functions to manipulate any matrix without solving them manually. So let’s get started.
What are NumPy Matrix Functions?
NumPy Matrix functions are those functions which allow us to create matrices easily and not only it is used to create matrices but also perform various matrix operations. Here, this matrix is just like a 2D array which is made up of rows and columns.
And these functions are mostly used in some matrix operations like addition, multiplication, transpose, and other mathematical calculations. NumPy has provided this matrix related function so that we can perform matrix operations in a easy way without solving them manually.
Different Types of NumPy Matrix Functions
Now let’s also discuss the different types of NumPy matrix functions which are used differently based on the purpose. So there are various purposes in which Matrix is used to solve problems. And these problems can be solved using Matrix operations. And for using Matrix operations, we have different types of Matrix operations, for example:
1. NumPy Matrix Creation Functions
These are used to create matrices (2D arrays). For example, these are the functions:
| Function | Purpose |
|---|---|
| np.array() | Create a matrix from Python lists |
| np.matrix() | Create matrix object (older, not recommended) |
| np.zeros() | Create matrix filled with zeros |
| np.ones() | Create matrix filled with ones |
| np.eye() | Create identity matrix |
| np.identity() | Create identity matrix of given size |
| np.full() | Create matrix with constant value |
| np.random.rand() | Random values between 0 and 1 |
| np.random.randn() | Random values from normal distribution |
| np.random.randint() | Random integer matrix |
2. NumPy Shape and Structure Operation Functions
These functions are used to change or inspect matrix structure. For example, these are the functions:
| Function | Purpose |
|---|---|
| matrix.shape | Returns rows and columns |
| matrix.ndim | Returns number of dimensions |
| matrix.size | Total number of elements |
| matrix.reshape() | Change matrix shape |
| matrix.T | Transpose the matrix |
| np.transpose() | Transpose using function |
| np.ravel() | Flatten matrix (view) |
| np.flatten() | Flatten matrix (copy) |
| np.squeeze() | Remove single-dimensional axes |
| np.expand_dims() | Add a new axis |
3. NumPy Matrix Arithmetic Operation Functions
These functions are used to perform basic mathematical operations on matrices. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.add() | Add two matrices element-wise |
| np.subtract() | Subtract matrices element-wise |
| np.multiply() | Element-wise multiplication |
| np.divide() | Element-wise division |
| np.power() | Raise elements to power |
| np.mod() | Element-wise modulus |
| np.abs() | Absolute value of elements |
4. NumPy Matrix Multiplication Operation Functions
These functions are very important in linear algebra and Machine Learning. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.dot() | Matrix multiplication |
| np.matmul() | Matrix multiplication (recommended) |
| @ operator | Matrix multiplication shortcut |
| np.inner() | Inner product of arrays |
| np.outer() | Outer product of vectors |
| np.tensordot() | Tensor dot product |
5. NumPy Statistical Operation Functions On Matrix
These functions are used to extract statistics from matrix data. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.sum() | Sum of elements |
| np.mean() | Average value |
| np.median() | Median value |
| np.std() | Standard deviation |
| np.var() | Variance |
| np.min() | Minimum value |
| np.max() | Maximum value |
| np.argmin() | Index of minimum value |
| np.argmax() | Index of maximum value |
6. NumPy Linear Algebra (linalg) Operation Functions
These functions are the core matrix operations used in ML, AI, and mathematics. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.linalg.det() | Find determinant |
| np.linalg.inv() | Find inverse of matrix |
| np.linalg.matrix_rank() | Rank of matrix |
| np.linalg.eig() | Eigenvalues & eigenvectors |
| np.linalg.eigh() | Eigenvalues of symmetric matrix |
| np.linalg.svd() | Singular Value Decomposition |
| np.linalg.solve() | Solve linear equations |
| np.linalg.norm() | Matrix or vector magnitude |
7. NumPy Matrix Comparison and Logical Operation Functions
These functions are used for condition checking. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.equal() | Check equality |
| np.not_equal() | Check inequality |
| np.greater() | Greater than comparison |
| np.less() | Less than comparison |
| np.any() | Check if any condition is true |
| np.all() | Check if all conditions are true |
| np.where() | Conditional selection |
8. NumPy Sorting and Indexing Operation Functions
These functions are used for rearranging matrix data. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.sort() | Sort matrix values |
| np.argsort() | Get sorted indices |
| np.argmax() | Index of maximum value |
| np.argmin() | Index of minimum value |
| np.take() | Extract elements by index |
| np.put() | Replace elements at indices |
9. NumPy Stacking and Splitting Matrices Functions
These functions are used to combine or divide matrices. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.vstack() | Vertical stacking |
| np.hstack() | Horizontal stacking |
| np.dstack() | Depth stacking |
| np.concatenate() | Join arrays along axis |
| np.stack() | Stack arrays with new axis |
| np.split() | Split matrix |
| np.vsplit() | Vertical split |
| np.hsplit() | Horizontal split |
10. NumPy Special Matrix Check Functions
These functions are helpful for validation. For example, these are the functions:
| Function | Purpose |
|---|---|
| np.allclose() | Check approximate equality |
| np.isfinite() | Check finite values |
| np.isnan() | Detect NaN values |
| np.isinf() | Detect infinite values |
Alright, so this was the complete list of NumPy Matrix functions with their purposes like for which reason they are used. However, we couldn’t discuss the code examples of every functions because there are 40 to 50 functions and it is impossible to complete in single article. That’s why we are not going to explain every function in this article, we will cover all the functions in upcoming articles.
We hope that this article was useful for you and helped you understand how NumPy matrix functions are used differently with the purposes. In case if you are still confused about any matrix function or want more explanation of any specific function, then you can freely ask your doubts in the comment section. We will try to answer your questions as soon as possible. So stay connected, and that’s all for today’s article. Thank you so much for reading this article till the end!
“So keep learning, keep growing!”




4 Comments
Nice 🙂👍
Nice
Nice
nice