What is numpy.c_ in Numpy from Python?

Overview

numpy.c is an indexing routine in NumPy that translates slice objects to concatenation along the second axis.

Syntax

np.c_[arrays]

Parameter value

numpy.c_ is not a function. Hence, it doesn’t take any parameter value.

Return value

numpy.c_ returns a concatenated array.

Code example

import numpy as np
# creating arrays
myarray1 = np.array([1, 2, 3])
myarray2 = np.array([4, 5, 6])
# using the numpy.c_
myarray = np.c_[myarray1, myarray2]
print(myarray)

Code explanation

  • Line 1: We import the numpy module.
  • Line 3-4: We create 1-D arrays myarray1 and myarray2 using the array() function.
  • Line 7: We use the numpy.c_ indexing routine to concatenate the two arrays. The result is assigned to a variable myarray.
  • Line 8: We print the array myarray.

Free Resources