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 arraysmyarray1 = 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
numpymodule. - Line 3-4: We create 1-D arrays
myarray1andmyarray2using thearray()function. - Line 7: We use the
numpy.c_indexing routine to concatenate the two arrays. The result is assigned to a variablemyarray. - Line 8: We print the array
myarray.