Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
numpy
python
communitycreator

What is the numpy.row_stack() function in NumPy?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The row_stack() function in NumPy is used to stack or arrange arrays in sequence vertically (row-wise).

Syntax

numpy.row_stack(tup)
Syntax for the row_stack() function in NumPy

Parameter value

The row_stack() function takes a single parameter value, tup, which represents the arrays that have the same shape along all the axes, except for the first axis.

Return value

The row_stack() function returns at least a 2-D array that is formed by stacking the given arrays vertically.

Example

import numpy as np
# creating input arrays
a = np.array([1, 2, 3, 4, 5])
b = np.array([6, 7, 8, 9, 10])
# stacking the arrays vertically
stacked_array = np.row_stack((a, b))
# printing the new array
print(stacked_array)
Implementing the row_stack() function

Explanation

  • Line 1: We import the numpy module.
  • Lines 3–4: We create input arrays, a and b, using the array() function.
  • Line 7: We vertically stack arrays a and b using the row_stack() function. The result is assigned to a variable, stacked_array.
  • Line 10: We print the newly stacked array, stacked_array.

RELATED TAGS

function
numpy
python
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring