numpy.atleast_2d() in Python
numpy.atleast_2d() in Python
The numpy.atleast_2d() function converts the inputs as arrays with at least two dimensions.
Syntax
numpy.atleast_2d(*arys)
Parameter
arys1, arys2, … : This parameter represents one or more array-like sequences where the non-array inputs are converted to arrays.
Return
This function returns an array (ndarray), or list of arrays, each with a.ndim >= 2.
Example 1
# Python Program explaining # numpy.atleast_2d() function import numpy as np int_num = 100 print ("Input number: \n", int_num) out_array = np.atleast_2d(int_num) print ("\n Output 2d array: \n", out_array)
Output
Input number: 100 Output 2d array: [[100]]
Example 2
# Python Program explaining # numpy.atleast_2d() function import numpy as np arr_list = [[22, 76, 60], [85, 192, 6]] print ("Input list: \n", arr_list) out_array = np.atleast_2d(arr_list) print ("\n Output Array: \n", out_array)
Output
Input list: [[22, 76, 60], [85, 192, 6]] Output Array: [[ 22 76 60] [ 85 192 6]]