Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Joining NumPy Array
Next article icon

numpy.vstack() in python

Last Updated : 25 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

numpy.vstack() is a function in NumPy used to stack arrays vertically (row-wise). It takes a sequence of arrays as input and returns a single array by stacking them along the vertical axis (axis 0).

Example: Vertical Stacking of 1D Arrays Using numpy.vstack()

Python
import numpy as geek  a = geek.array([ 1, 2, 3] ) print ("1st Input array : \n", a)   b = geek.array([ 4, 5, 6] ) print ("2nd Input array : \n", b)   res = geek.vstack((a, b)) print ("Output vertically stacked array:\n ", res) 

Output
1st Input array :   [1 2 3] 2nd Input array :   [4 5 6] Output vertically stacked array:   [[1 2 3]  [4 5 6]] 

Explanation: The two 1D arrays a and b are stacked vertically using np.vstack(), combining them into a 2D array where each input array forms a row.

Syntax

numpy.vstack(tup)

Parameters:

  • tup: [sequence of ndarrays] Tuple containing arrays to be stacked. The arrays must have the same shape along all but the first axis.

Return: [stacked ndarray] The stacked array of the input arrays.

Vertical Stacking of 2D Arrays Using numpy.vstack()

This code shows how to vertically stack two 2D arrays using numpy.vstack(), resulting in a combined 2D array.

Python
import numpy as geek  a = geek.array([[ 1, 2, 3], [ -1, -2, -3]] ) print ("1st Input array : \n", a)   b = geek.array([[ 4, 5, 6], [ -4, -5, -6]] ) print ("2nd Input array : \n", b)   res = geek.vstack((a, b)) print ("Output stacked array :\n ", res) 

Output
1st Input array :   [[ 1  2  3]  [-1 -2 -3]] 2nd Input array :   [[ 4  5  6]  [-4 -5 -6]] Output stacked array :   [[ 1  2  3]  [-1 -2 -3]  [ 4  5  6]  [-4 -5 -6]] 

Explanation: Two 2D arrays a and b are vertically stacked, creating a new 2D array where each original array becomes a set of rows in the resulting array.


Next Article
Joining NumPy Array
author
jana_sayantan
Improve
Article Tags :
  • Python
  • Python numpy-arrayManipulation
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • NumPy Tutorial - Python Library
    NumPy (short for Numerical Python ) is one of the most fundamental libraries in Python for scientific computing. It provides support for large, multi-dimensional arrays and matrices along with a collection of mathematical functions to operate on arrays. At its core it introduces the ndarray (n-dimen
    3 min read
  • Introduction

    • NumPy Introduction
      NumPy(Numerical Python) is a fundamental library for Python numerical computing. It provides efficient multi-dimensional array objects and various mathematical functions for handling large datasets making it a critical tool for professionals in fields that require heavy computation. Table of Content
      7 min read

    • Python NumPy
      Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Besides its obvious scientific uses, Numpy can also be used as an efficient
      6 min read

    • NumPy Array in Python
      NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C
      2 min read

    • Basics of NumPy Arrays
      NumPy stands for Numerical Python. It is a Python library used for working with an array. In Python, we use the list for the array but it's slow to process. NumPy array is a powerful N-dimensional array object and is used in linear algebra, Fourier transform, and random number capabilities. It provi
      5 min read

    • Numpy - ndarray
      ndarray((short for N-dimensional array)) is a core object in NumPy. It is a homogeneous array which means it can hold elements of the same data type. It is a multi-dimensional data structure that enables fast and efficient manipulation of large dataset Let's understand with a simple example: [GFGTAB
      3 min read

    • Data type Object (dtype) in NumPy Python
      Every ndarray has an associated data type (dtype) object. This data type object (dtype) informs us about the layout of the array. This means it gives us information about: Type of the data (integer, float, Python object, etc.)Size of the data (number of bytes)The byte order of the data (little-endia
      3 min read

    Creating NumPy Array

    • Numpy - Array Creation
      Numpy Arrays are grid-like structures similar to lists in Python but optimized for numerical operations. The most straightforward way to create a NumPy array is by converting a regular Python list into an array using the np.array() function. Let's understand this with the help of an example: [GFGTAB
      5 min read

    • numpy.arange() in Python
      numpy.arange() function creates an array of evenly spaced values within a given interval. It is similar to Python's built-in range() function but returns a NumPy array instead of a list. Let's understand with a simple example: [GFGTABS] Python import numpy as np #create an array arr= np.arange(5 , 1
      2 min read

    • numpy.zeros() in Python
      numpy.zeros() function creates a new array of specified shapes and types, filled with zeros. It is beneficial when you need a placeholder array to initialize variables or store intermediate results. We can create 1D array using numpy.zeros(). Let's understand with the help of an example: [GFGTABS] P
      2 min read

    • NumPy - Create array filled with all ones
      To create an array filled with all ones, given the shape and type of array, we can use numpy.ones() method of NumPy library in Python. [GFGTABS] Python import numpy as np array = np.ones(5) print(array) [/GFGTABS]Output: [1. 1. 1. 1. 1.] 2D Array of OnesWe can also create a 2D array (matrix) filled
      2 min read

    • NumPy - linspace() Function
      linspace() function in NumPy returns an array of evenly spaced numbers over a specified range. Unlike the range() function in Python that generates numbers with a specific step size. linspace() allows you to specify the total number of points you want in the array, and NumPy will calculate the spaci
      3 min read

    • numpy.eye() in Python
      numpy.eye() is a function in the NumPy library that creates a 2D array with ones on the diagonal and zeros elsewhere. This function is often used to generate identity matrices with ones along the diagonal and zeros in all other positions. Let's understand with the help of an example: [GFGTABS] Pytho
      2 min read

    • Creating a one-dimensional NumPy array
      One-dimensional array contains elements only in one dimension. In other words, the shape of the NumPy array should contain only one value in the tuple. We can create a 1-D array in NumPy using the array() function, which converts a Python list or iterable object. [GFGTABS] Python import numpy as np
      2 min read

    • How to create an empty and a full NumPy array?
      Creating arrays is a basic operation in NumPy. Empty array: This array isn’t initialized with any specific values. It’s like a blank page, ready to be filled with data later. However, it will contain random leftover values in memory until you update it.Full array: This is an array where all the elem
      2 min read

    • Create a Numpy array filled with all zeros - Python
      In this article, we will learn how to create a Numpy array filled with all zeros, given the shape and type of array. We can use Numpy.zeros() method to do this task. Let's understand with the help of an example: [GFGTABS] Python import numpy as np # Create a 1D array of zeros with 5 elements array_1
      2 min read

    • How to generate 2-D Gaussian array using NumPy?
      In this article, let us discuss how to generate a 2-D Gaussian array using NumPy. To create a 2 D Gaussian array using the Numpy python module. Functions used:numpy.meshgrid()- It is used to create a rectangular grid out of two given one-dimensional arrays representing the Cartesian indexing or Matr
      2 min read

    • How to create a vector in Python using NumPy
      NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy is basically used for creating array of n dimensions. Vector are built
      5 min read

    • Python - Numpy fromrecords() method
      numpy.fromrecords() method is a powerful tool in the NumPy library that allows you to create structured arrays from a sequence of tuples or other array-like objects. Let's understand the help of an example: [GFGTABS] Python import numpy as np # Define a list of records records = [(1, 'Alice'
      2 min read

    NumPy Array Manipulation

    • NumPy Copy and View of Array
      While working with NumPy, you might have seen some functions return the copy whereas some functions return the view. The main difference between copy and view is that the copy is the new array whereas the view is the view of the original array. In other words, it can be said that the copy is physica
      4 min read

    • How to Copy NumPy array into another array?
      Many times there is a need to copy one array to another. Numpy provides the facility to copy array using different methods. In this Copy NumPy Array into Another ArrayThere are various ways to copies created in NumPy arrays in Python, here we are discussing some generally used methods for copies cre
      3 min read

    • Appending values at the end of an NumPy array
      Let us see how to append values at the end of a NumPy array. Adding values at the end of the array is a necessary task especially when the data is not fixed and is prone to change. For this task, we can use numpy.append() and numpy.concatenate(). This function can help us to append a single value as
      4 min read

    • How to swap columns of a given NumPy array?
      In this article, let's discuss how to swap columns of a given NumPy array. Approach : Import NumPy moduleCreate a NumPy arraySwap the column with IndexPrint the Final array Example 1: Swapping the column of an array. C/C++ Code # importing Module import numpy as np # creating array with shape(4,3) m
      2 min read

    • Insert a new axis within a NumPy array
      This post deals with the ways to increase the dimension of an array in NumPy. NumPy provides us with two different built-in functions to increase the dimension of an array i.e., 1D array will become 2D array2D array will become 3D array3D array will become 4D array4D array will become 5D arrayAdd a
      4 min read

    • numpy.hstack() in Python
      numpy.hstack() function is used to stack the sequence of input arrays horizontally (i.e. column wise) to make a single array. Syntax : numpy.hstack(tup) Parameters : tup : [sequence of ndarrays] Tuple containing arrays to be stacked. The arrays must have the same shape along all but the second axis.
      2 min read

    • numpy.vstack() in python
      numpy.vstack() is a function in NumPy used to stack arrays vertically (row-wise). It takes a sequence of arrays as input and returns a single array by stacking them along the vertical axis (axis 0). Example: Vertical Stacking of 1D Arrays Using numpy.vstack() [GFGTABS] Python import numpy as geek a
      2 min read

    • Joining NumPy Array
      NumPy provides various functions to combine arrays. In this article, we will discuss some of the major ones. numpy.concatenatenumpy.stacknumpy.blockMethod 1: Using numpy.concatenate()The concatenate function in NumPy joins two or more arrays along a specified axis. Syntax:numpy.concatenate((array1,
      2 min read

    • Combining a one and a two-dimensional NumPy Array
      Sometimes we need to combine 1-D and 2-D arrays and display their elements. Numpy has a function named as numpy.nditer(), which provides this facility. Syntax: numpy.nditer(op, flags=None, op_flags=None, op_dtypes=None, order='K', casting='safe', op_axes=None, itershape=None, buffersize=0) Example 1
      2 min read

    • Python | Numpy np.ma.concatenate() method
      With the help of np.ma.concatenate() method, we can concatenate two arrays with the help of np.ma.concatenate() method. Syntax : np.ma.concatenate([list1, list2]) Return : Return the array after concatenation. Example #1 : In this example we can see that by using np.ma.concatenate() method, we are a
      1 min read

    • Python | Numpy dstack() method
      With the help of numpy.dstack() method, we can get the combined array index by index and store like a stack by using numpy.dstack() method. Syntax : numpy.dstack((array1, array2)) Return : Return combined array index by index. Example #1 : In this example we can see that by using numpy.dstack() meth
      1 min read

    • Splitting Arrays in NumPy
      NumPy arrays are an essential tool for scientific computing. However, at times, it becomes necessary to manipulate and analyze specific parts of the data. This is where array splitting comes into play, allowing you to break down an array into smaller sub-arrays, making the data more manageable. It i
      6 min read

    • How to compare two NumPy arrays?
      Here we will be focusing on the comparison done using NumPy on arrays. Comparing two NumPy arrays determines whether they are equivalent by checking if every element at each corresponding index is the same. Method 1: We generally use the == operator to compare two NumPy arrays to generate a new arra
      2 min read

    • Find the union of two NumPy arrays
      To find union of two 1-dimensional arrays we can use function numpy.union1d() of Python Numpy library. It returns unique, sorted array with values that are in either of the two input arrays. Syntax: numpy.union1d(array1, array2) Note The arrays given in input are flattened if they are not 1-dimensio
      2 min read

    • Find unique rows in a NumPy array
      In this article, we will discuss how to find unique rows in a NumPy array. To find unique rows in a NumPy array we are using numpy.unique() function of NumPy library. Syntax of np.unique() in Python Syntax: numpy.unique() Parameter: ar: arrayreturn_index: Bool, if True return the indices of the inpu
      3 min read

    • Python | Numpy np.unique() method
      With the help of np.unique() method, we can get the unique values from an array given as parameter in np.unique() method. Syntax : np.unique(Array) Return : Return the unique of an array. Example #1 : In this example we can see that by using np.unique() method, we are able to get the unique values f
      1 min read

    • numpy.trim_zeros() in Python
      numpy.trim_zeros function is used to trim the leading and/or trailing zeros from a 1-D array or sequence. Syntax: numpy.trim_zeros(arr, trim) Parameters: arr : 1-D array or sequence trim : trim is an optional parameter with default value to be 'fb'(front and back) we can either select 'f'(front) and
      2 min read

    Matrix in NumPy

    • Matrix manipulation in Python
      In python matrix can be implemented as 2D list or 2D Array. Forming matrix from latter, gives the additional functionalities for performing various operations in matrix. These operations and array are defines in module "numpy". Operation on Matrix : 1. add() :- This function is used to perform eleme
      4 min read

    • numpy matrix operations | empty() function
      numpy.matlib.empty() is another function for doing matrix operations in numpy.It returns a new matrix of given shape and type, without initializing entries. Syntax : numpy.matlib.empty(shape, dtype=None, order='C') Parameters : shape : [int or tuple of int] Shape of the desired output empty matrix.
      1 min read

    • numpy matrix operations | zeros() function
      numpy.matlib.zeros() is another function for doing matrix operations in numpy. It returns a matrix of given shape and type, filled with zeros. Syntax : numpy.matlib.zeros(shape, dtype=None, order='C') Parameters : shape : [int, int] Number of rows and columns in the output matrix.If shape has length
      2 min read

    • numpy matrix operations | ones() function
      numpy.matlib.ones() is another function for doing matrix operations in numpy. It returns a matrix of given shape and type, filled with ones. Syntax : numpy.matlib.ones(shape, dtype=None, order='C') Parameters : shape : [int, int] Number of rows and columns in the output matrix.If shape has length on
      2 min read

    • numpy matrix operations | eye() function
      numpy.matlib.eye() is another function for doing matrix operations in numpy. It returns a matrix with ones on the diagonal and zeros elsewhere. Syntax : numpy.matlib.eye(n, M=None, k=0, dtype='float', order='C') Parameters : n : [int] Number of rows in the output matrix. M : [int, optional] Number o
      2 min read

    • numpy matrix operations | identity() function
      numpy.matlib.identity() is another function for doing matrix operations in numpy. It returns a square identity matrix of given input size. Syntax : numpy.matlib.identity(n, dtype=None) Parameters : n : [int] Number of rows and columns in the output matrix. dtype : [optional] Desired output data-type
      1 min read

    • Adding and Subtracting Matrices in Python
      In this article, we will discuss how to add and subtract elements of the matrix in Python. Example: Suppose we have two matrices A and B. A = [[1,2],[3,4]] B = [[4,5],[6,7]] then we get A+B = [[5,7],[9,11]] A-B = [[-3,-3],[-3,-3]] Now let us try to implement this using Python 1. Adding elements of t
      4 min read

    • Matrix Multiplication in NumPy
      Let us see how to compute matrix multiplication with NumPy. We will be using the numpy.dot() method to find the product of 2 matrices. For example, for two matrices A and B. A = [[1, 2], [2, 3]] B = [[4, 5], [6, 7]] So, A.B = [[1*4 + 2*6, 2*4 + 3*6], [1*5 + 2*7, 2*5 + 3*7] So the computed answer wil
      2 min read

    • Numpy ndarray.dot() function | Python
      The numpy.ndarray.dot() function computes the dot product of two arrays. It is widely used in linear algebra, machine learning and deep learning for operations like matrix multiplication and vector projections. Example: [GFGTABS] Python import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5,
      2 min read

    • NumPy | Vector Multiplication
      NumPy is a Python library used for performing numerical computations. It provides an efficient way to work with vectors and matrices especially when performing vector multiplication operations. It is used in various applications such as data science, machine learning, physics simulations and many mo
      5 min read

    • How to calculate dot product of two vectors in Python?
      dot product or also known as the scalar product is an algebraic operation that takes two equal-length sequences of numbers and returns a single number. Let us given two vectors A and B, and we have to find the dot product of two vectors. Given that, [Tex]A = a_1i + a_2j + a_3k [/Tex][Tex]B = b_1i +
      3 min read

    • Multiplication of two Matrices in Single line using Numpy in Python
      Matrix multiplication is an operation that takes two matrices as input and produces single matrix by multiplying rows of the first matrix to the column of the second matrix.In matrix multiplication make sure that the number of columns of the first matrix should be equal to the number of rows of the
      3 min read

    • Python | Numpy np.eigvals() method
      With the help of np.eigvals() method, we can get the eigen values of a matrix by using np.eigvals() method. Syntax : np.eigvals(matrix) Return : Return the eigen values of a matrix. Example #1 : In this example we can see that by using np.eigvals() method, we are able to get the eigen values of a ma
      1 min read

    • How to Calculate the determinant of a matrix using NumPy?
      The determinant of a square matrix is a special number that helps determine whether the matrix is invertible and how it transforms space. It is widely used in linear algebra, geometry and solving equations. NumPy provides built-in functions to easily compute the determinant of a matrix, let's explor
      2 min read

    • Python | Numpy matrix.transpose()
      With the help of Numpy matrix.transpose() method, we can find the transpose of the matrix by using the matrix.transpose()method in Python. Numpy matrix.transpose() Syntax Syntax : matrix.transpose() Parameter: No parameters; transposes the matrix it is called on. Return : Return transposed matrix Wh
      3 min read

    • Python | Numpy matrix.var()
      With the help of Numpy matrix.var() method, we can find the variance of a matrix by using the matrix.var() method. Syntax : matrix.var() Return : Return variance of a matrix Example #1 : In this example we can see that by using matrix.var() method we are able to find the variance of a given matrix.
      1 min read

    • Compute the inverse of a matrix using NumPy
      The inverse of a matrix is just a reciprocal of the matrix as we do in normal arithmetic for a single number which is used to solve the equations to find the value of unknown variables. The inverse of a matrix is that matrix which when multiplied with the original matrix will give as an identity mat
      2 min read

    Operations on NumPy Array

    • Numpy | Binary Operations
      Binary operators acts on bits and performs bit by bit operation. Binary operation is simply a rule for combining two values to create a new value. numpy.bitwise_and() : This function is used to Compute the bit-wise AND of two array element-wise. This function computes the bit-wise AND of the underly
      8 min read

    • Numpy | Mathematical Function
      NumPy contains a large number of various mathematical operations. NumPy provides standard trigonometric functions, functions for arithmetic operations, handling complex numbers, etc. Trigonometric Functions –NumPy has standard trigonometric functions which return trigonometric ratios for a given ang
      9 min read

    • Numpy - String Functions & Operations
      NumPy String functions belong to the numpy.char module and are designed to perform element-wise operations on arrays. These functions can help to handle and manipulate string data efficiently. Table of Content String OperationsString Information String Comparison In this article, we’ll explore the v
      5 min read

    Reshaping NumPy Array

    • Reshape NumPy Array
      NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy is basically used for creating array of n dimensions.Reshaping numpy a
      5 min read

    • Python | Numpy matrix.resize()
      With the help of Numpy matrix.resize() method, we are able to resize the shape of the given matrix. Remember all elements should be covered after resizing the given matrix. Syntax : matrix.resize(shape) Return: new resized matrix Example #1 : In the given example we are able to resize the given matr
      1 min read

    • Python | Numpy matrix.reshape()
      With the help of Numpy matrix.reshape() method, we are able to reshape the shape of the given matrix. Remember all elements should be covered after reshaping the given matrix. Syntax : matrix.reshape(shape) Return: new reshaped matrix Example #1 : In the given example we are able to reshape the give
      1 min read

    • NumPy Array Shape
      The shape of an array can be defined as the number of elements in each dimension. Dimension is the number of indices or subscripts, that we require in order to specify an individual element of an array. How can we get the Shape of an Array?In NumPy, we will use an attribute called shape which return
      2 min read

    • Change the dimension of a NumPy array
      Let's discuss how to change the dimensions of an array. In NumPy, this can be achieved in many ways. Let's discuss each of them. Method #1: Using Shape() Syntax : array_name.shape() C/C++ Code # importing numpy import numpy as np def main(): # initialising array print('Initialised array') gfg = np.a
      3 min read

    • numpy.ndarray.resize() function - Python
      numpy.ndarray.resize() function change shape and size of array in-place. Syntax : numpy.ndarray.resize(new_shape, refcheck = True) Parameters : new_shape :[tuple of ints, or n ints] Shape of resized array. refcheck :[bool, optional] If False, reference count will not be checked. Default is True. Ret
      1 min read

    • Flatten a Matrix in Python using NumPy
      Let's discuss how to flatten a Matrix using NumPy in Python. By using ndarray.flatten() function we can flatten a matrix to one dimension in python. Syntax:numpy_array.flatten(order='C') order:'C' means to flatten in row-major.'F' means to flatten in column-major.'A' means to flatten in column-major
      1 min read

    • numpy.moveaxis() function | Python
      numpy.moveaxis() function allows you to rearrange axes of an array. It is used when you need to shift dimensions of an array to different positions without altering the actual data. The syntax for the numpy.moveaxis() function is as follows: numpy.moveaxis(array, source, destination) Parameters: arr
      2 min read

    • numpy.swapaxes() function - Python
      numpy.swapaxes() function allow us to interchange two axes of a multi-dimensional NumPy array. It focuses on swapping only two specified axes while leaving the rest unchanged. It is used to rearrange the structure of an array without altering its actual data. The syntax of numpy.swapaxes() is: numpy
      2 min read

    • Python | Numpy matrix.swapaxes()
      With the help of matrix.swapaxes() method, we are able to swap the axes a matrix by using the same method. Syntax : matrix.swapaxes() Return : Return matrix having interchanged axes Example #1 : In this example we are able to swap the axes of a matrix by using matrix.swapaxes() method. # import the
      1 min read

    • numpy.vsplit() function | Python
      numpy.vsplit() function split an array into multiple sub-arrays vertically (row-wise). vsplit is equivalent to split with axis=0 (default), the array is always split along the first axis regardless of the array dimension. Syntax : numpy.vsplit(arr, indices_or_sections) Parameters : arr : [ndarray] A
      2 min read

    • numpy.hsplit() function | Python
      The numpy.hsplit() function is used to split a NumPy array into multiple sub-arrays horizontally (column-wise). It is equivalent to using the numpy.split() function with axis=1. Regardless of the dimensionality of the input array, numpy.hsplit() always divides the array along its second axis (column
      2 min read

    • Numpy MaskedArray.reshape() function | Python
      numpy.MaskedArray.reshape() function is used to give a new shape to the masked array without changing its data.It returns a masked array containing the same data, but with a new shape. The result is a view on the original array; if this is not possible, a ValueError is raised. Syntax : numpy.ma.resh
      3 min read

    • Python | Numpy matrix.squeeze()
      With the help of matrix.squeeze() method, we are able to squeeze the size of a matrix by using the same method. But remember one thing we use this method on Nx1 size of matrix which gives out as 1xN matrix. Syntax : matrix.squeeze() Return : Return a squeezed matrix Example #1 : In this example we a
      1 min read

    Indexing NumPy Array

    • Basic Slicing and Advanced Indexing in NumPy
      Indexing a NumPy array means accessing the elements of the NumPy array at the given index. There are two types of indexing in NumPy: basic indexing and advanced indexing. Slicing a NumPy array means accessing the subset of the array. It means extracting a range of elements from the data. In this tut
      5 min read

    • numpy.compress() in Python
      The numpy.compress() function returns selected slices of an array along mentioned axis, that satisfies an axis. Syntax: numpy.compress(condition, array, axis = None, out = None) Parameters : condition : [array_like]Condition on the basis of which user extract elements. Applying condition on input_ar
      2 min read

    • Accessing Data Along Multiple Dimensions Arrays in Python Numpy
      NumPy (Numerical Python) is a Python library that comprises of multidimensional arrays and numerous functions to perform various mathematical and logical operations on them. NumPy also consists of various functions to perform linear algebra operations and generate random numbers. NumPy is often used
      3 min read

    • How to access different rows of a multidimensional NumPy array?
      Let us see how to access different rows of a multidimensional array in NumPy. Sometimes we need to access different rows of multidimensional NumPy array-like first row, the last two rows, and even the middle two rows, etc. In NumPy , it is very easy to access any rows of a multidimensional array. Al
      3 min read

    • numpy.tril_indices() function | Python
      numpy.tril_indices() function return the indices for the lower-triangle of an (n, m) array. Syntax : numpy.tril_indices(n, k = 0, m = None) Parameters : n : [int] The row dimension of the arrays for which the returned indices will be valid. k : [int, optional] Diagonal offset. m : [int, optional] Th
      1 min read

    Arithmetic operations on NumPyArray

    • NumPy Array Broadcasting
      Broadcasting simplifies mathematical operations on arrays with different shapes. It enables NumPy to efficiently apply operations element-wise without explicitly copying or reshaping data. It automatically adjusts the smaller array to match the shape of the larger array by replicating its values alo
      6 min read

    • Estimation of Variable | set 1
      Variability: It is the import dimension that measures the data variation i.e. whether the data is spread out or tightly clustered. Also known as Dispersion When working on data sets in Machine Learning or Data Science, involves many steps - variance measurement, reduction, and distinguishing random
      3 min read

    • Python: Operations on Numpy Arrays
      NumPy is a Python package which means 'Numerical Python'. It is the library for logical computing, which contains a powerful n-dimensional array object, gives tools to integrate C, C++ and so on. It is likewise helpful in linear based math, arbitrary number capacity and so on. NumPy exhibits can lik
      3 min read

    • How to use the NumPy sum function?
      NumPy's sum() function is extremely useful for summing all elements of a given array in Python. In this article, we'll be going over how to utilize this function and how to quickly use this to advance your code's functionality. Let's go over how to use these functions and the benefits of using this
      4 min read

    • numpy.divide() in Python
      numpy.divide(arr1, arr2, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : Array element from first array is divided by elements from second element (all happens element-wise). Both arr1 and arr2 must have same shape and element in arr2 must not be zero; otherwise it will
      3 min read

    • numpy.inner() in python
      numpy.inner(arr1, arr2): Computes the inner product of two arrays. Parameters : arr1, arr2 : array to be evaluated. Return: Inner product of the two arrays. Code #1 : # Python Program illustrating # numpy.inner() method import numpy as geek # Scalars product = geek.inner(5, 4) print("inner Prod
      1 min read

    • Absolute Deviation and Absolute Mean Deviation using NumPy | Python
      Absolute value: Absolute value or the modulus of a real number x is the non-negative value of x without regard to its sign. For example absolute value of 7 is 7 and the absolute value of -7 is also 7. Deviation: Deviation is a measure of the difference between the observed value of a variable and so
      3 min read

    • Calculate standard deviation of a Matrix in Python
      In this article we will learn how to calculate standard deviation of a Matrix using Python. Standard deviation is used to measure the spread of values within the dataset. It indicates variations or dispersion of values in the dataset and also helps to determine the confidence in a model’s statistica
      2 min read

    • numpy.gcd() in Python
      numpy.gcd(arr1, arr2, out = None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None) : This mathematical function helps user to calculate GCD value of |arr1| and |arr2| elements. Greatest Common Divisor (GCD) of two or more numbers, which are not all zero, is the largest positive number
      1 min read

    Linear Algebra in NumPy Array

    • Numpy | Linear Algebra
      The Linear Algebra module of NumPy offers various methods to apply linear algebra on any numpy array.One can find: rank, determinant, trace, etc. of an array.eigen values of matricesmatrix and vector products (dot, inner, outer,etc. product), matrix exponentiationsolve linear or tensor equations and
      6 min read

    • Get the QR factorization of a given NumPy array
      In this article, we will discuss QR decomposition or QR factorization of a matrix. QR factorization of a matrix is the decomposition of a matrix say 'A' into 'A=QR' where Q is orthogonal and R is an upper-triangular matrix. We factorize the matrix using numpy.linalg.qr() function. Syntax : numpy.lin
      2 min read

    • How to get the magnitude of a vector in NumPy?
      The fundamental feature of linear algebra are vectors, these are the objects having both direction and magnitude. In Python, NumPy arrays can be used to depict a vector. There are mainly two ways of getting the magnitude of vector: By defining an explicit function which computes the magnitude of a g
      3 min read

    • How to compute the eigenvalues and right eigenvectors of a given square array using NumPY?
      In this article, we will discuss how to compute the eigenvalues and right eigenvectors of a given square array using NumPy library. Example: Suppose we have a matrix as: [[1,2], [2,3]] Eigenvalue we get from this matrix or square array is: [-0.23606798 4.23606798] Eigenvectors of this matrix are: [[
      2 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences