numpy.atleast_2d() in Python
The numpy.atleast_2d() function converts the inputs as arrays with at least two dimensions.
Syntax
1 2 3 |
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
1 2 3 4 5 6 7 8 9 |
# 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
1 2 3 4 5 6 |
Input number: 100 Output 2d array: [[100]] |
Example 2
1 2 3 4 5 6 7 8 9 10 |
# 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
1 2 3 4 5 6 7 |
Input list: [[22, 76, 60], [85, 192, 6]] Output Array: [[ 22 76 60] [ 85 192 6]] |