Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • 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:
Ways to Convert a Python Dictionary to a NumPy Array
Next article icon

Ways to Add Row/Columns in Numpy Array - Python

Last Updated : 24 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Adding rows or columns to a NumPy array means appending new data along a specific axis. For example, if you have a 2D array like [[1, 2], [3, 4]] and you add a new row [5, 6], the array becomes [[1, 2], [3, 4], [5, 6]]. Similarly, adding a column [7, 8, 9] to a 3x2 array transforms it into a 3x3 array.

Let’s explore different ways to do this efficiently using NumPy.

Add columns in the Numpy array

We can add columns to a NumPy array using append(), concatenate(), insert(), column_stack() or hstack() with axis=1. Just make sure the new column has the same number of rows as the original array.

Using np.append()

np.append() adds values to a NumPy array along a specified axis or flattens if axis is not set.

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([[1], [2], [3]])  c = np.append(a, b, axis=1) print(c) 

Output
[[ 1  2  3  1]  [45  4  7  2]  [ 9  6 10  3]] 

Explanation:

  • a is base array and b is array to append.
  • np.append(a, b, axis=1) adds b as a new column to a, resulting in a 3x4 matrix
  • whereas, axis=1 append along columns (i.e., horizontally).

Using np.concatenate()

np.concatenate() joins two or more arrays along a specified axis.

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([[1], [2], [3]])  c = np.concatenate([a, b], axis=1) print (c) 

Output
[[ 1  2  3  1]  [45  4  7  2]  [ 9  6 10  3]] 

Explanation:

  • np.concatenate([a, b], axis=1) is joining list of two arrays [a, b].
  • axis=1 join along columns (horizontally).

Using np.insert()

np.insert() inserts values into a NumPy array at specified positions along a given axis.

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([[1], [2], [3]])  c = np.insert(a, 3, b.flatten(), axis=1) print(c) 

Output
[[ 1  2  3  1]  [45  4  7  2]  [ 9  6 10  3]] 

Explanation:

  • b.flatten() converts b to a 1D array [1, 2, 3].
  • np.insert(a, 3, b.flatten(), axis=1) inserts b as the 4th column (index 3), one value per row.

Using np.hstack()   

np.hstack() horizontally stacks arrays (adds columns side by side).

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([1, 2, 3])  c = np.hstack((a, np.atleast_2d(b).T)) print (c) 

Output
[[ 1  2  3  1]  [45  4  7  2]  [ 9  6 10  3]] 

Explanation:

  • np.atleast_2d(b).T converts b to a 3×1 column.
  • np.hstack() adds the column to the right of a.

Using np.column_stack()  

np.column_stack() stacks 1D or 2D arrays as columns to form a 2D array.

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([1, 2, 3])  c = np.column_stack((a, b)) print (c) 

Output
[[ 1  2  3  1]  [45  4  7  2]  [ 9  6 10  3]] 

Explanation: np.column_stack((a, b)) stacks b as a new column to the right of a.

Add row in Numpy array

To add rows to a NumPy array, use functions like np.r_, np.insert(), np.vstack() or np.append() with axis=0.

Using np.r_ 

np.r_ is a shortcut for stacking arrays vertically (row-wise).

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([1, 2, 3])  c = np.r_[a,[b]] print (c) 

Output
[[ 1  2  3]  [45  4  7]  [ 9  6 10]  [ 1  2  3]] 

Explanation: np.r_[a, [b]] appends b as a new row at the bottom of a.

Using np.insert()

np.insert() can add rows to a NumPy array by specifying the row index and using axis=0.

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([1, 2, 3])  n = a.shape[0]   c = np.insert(a, n, b, axis=0) print(c) 

Output
[[ 1  2  3]  [45  4  7]  [ 9  6 10]  [ 1  2  3]] 

Explanation:

  • n = a.shape[0] gets row count (3).
  • np.insert(a, n, b, axis=0) inserts b as a new row at the end of a.

Using np.vstack()  

np.vstack() adds arrays vertically, stacking them as new rows.

Python
import numpy as np a = np.array([[1, 2, 3], [45, 4, 7], [9, 6, 10]]) b = np.array([1, 2, 3])  c = np.vstack ((a, b)) print (c) 

Output
[[ 1  2  3]  [45  4  7]  [ 9  6 10]  [ 1  2  3]] 

Explanation: np.vstack((a, b)) vertically stacks b as a new row under a.

Using numpy.append()

You can add rows to an empty NumPy array using the numpy.append() function.

Example 1: Adding new rows to an empty 2-D array

Python
import numpy as np     a = np.empty((0,2), int) print("Empty array:\n", a)  a = np.append(a, np.array([[10,20]]), axis=0) a = np.append(a, np.array([[40,50]]), axis=0)  print("\nNew array:\n",a ) 

Output
Empty array:  []  New array:  [[10 20]  [40 50]] 

Explanation:

  • np.empty((0,2), int) creates an empty array with 0 rows and 2 columns.
  • np.append(..., axis=0) appends new rows to a (row-wise), first adds [10, 20] then [40, 50].

Example 2: Adding new rows to an existing 2-D array.

Python
import numpy as np    a = np.array([[1, 2, 3], [4, 5, 6]]) print("Original array:\n", a)  b = np.array([[7, 8, 9], [10, 11, 12]]) c = np.append(a, b, axis=0) print("\nNew array:\n", c) 

Output
Original array:  [[1 2 3]  [4 5 6]]  New array:  [[ 1  2  3]  [ 4  5  6]  [ 7  8  9]  [10 11 12]] 

Explanation: a is a 2D array, and b has the same number of columns. Using np.append(axis=0), the new rows are added to the bottom of the original array.

Related Articles:

  • np.append()
  • np.concatenate
  • np.insert()
  • np.hstack() 
  • np.column_stack() 
  • np.vstack()  

Next Article
Ways to Convert a Python Dictionary to a NumPy Array

G

garg_ak0109
Improve
Article Tags :
  • Python
  • Python-numpy
  • Python numpy-program
Practice Tags :
  • python

Similar Reads

    Python | Ways to add row/columns in numpy array
    Adding rows or columns to a NumPy array means appending new data along a specific axis. For example, if you have a 2D array like [[1, 2], [3, 4]] and you add a new row [5, 6], the array becomes [[1, 2], [3, 4], [5, 6]]. Similarly, adding a column [7, 8, 9] to a 3x2 array transforms it into a 3x3 arr
    5 min read
    Ways to Convert a Python Dictionary to a NumPy Array
    The task of converting a dictionary to a NumPy array involves transforming the dictionary’s key-value pairs into a format suitable for NumPy. In Python, there are different ways to achieve this conversion, depending on the structure and organization of the resulting array.For example, consider a dic
    3 min read
    Different Ways to Create Numpy Arrays in Python
    Creating NumPy arrays is a fundamental aspect of working with numerical data in Python. NumPy provides various methods to create arrays efficiently, catering to different needs and scenarios. In this article, we will see how we can create NumPy arrays using different ways and methods. Ways to Create
    3 min read
    numpy.column_stack() in Python
    numpy.column_stack() function is used to stack 1-D arrays as columns into a 2-D array.It takes a sequence of 1-D arrays and stack them as columns to make a single 2-D array. 2-D arrays are stacked as-is, just like with hstack function. Syntax : numpy.column_stack(tup) Parameters : tup : [sequence of
    2 min read
    Python | Numpy numpy.ndarray.__add__()
    With the help of Numpy numpy.ndarray.__add__(), we can add a particular value that is provided as a parameter in the ndarray.__add__() method. Value will be added to each and every element in a numpy array. Syntax: ndarray.__add__($self, value, /) Return: self+value Example #1 : In this example we c
    1 min read
    How to Swap Two Rows in a NumPy Array
    One common task you might encounter when working with NumPy arrays is the need to swap two rows. Swapping rows can be essential in data preprocessing, reshaping data, or reordering data to perform specific analyses in Python. In this article, we will explore different methods to swap two rows in a N
    4 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