numpy.atleast_1d() in Python
The numpy.atleast_1d() function converts the inputs to arrays with at least one dimension.
Syntax
1 2 3 |
numpy.atleast_1d(*arys) |
Parameter
arys1, arys2, … : This parameter represents one or more input arrays.
Return
This function returns an array, or list of arrays, each with a.ndim >= 1.
Example 1
1 2 3 4 5 6 7 8 9 |
# Python Program explaining # numpy.atleast_1d() function import numpy as np int_num = 100 print ("Input number: \n", int_num) out_array = np.atleast_1d(int_num) print ("\n output 1d array: \n", out_array) |
Output
1 2 3 4 5 6 |
Input number: 100 output 1d array: [100] |
Example 2
1 2 3 4 5 6 7 8 9 10 |
# Python Program explaining # numpy.atleast_1d() function import numpy as np arr_list = [[22, 76, 60], [85, 192, 6]] print ("Input list: \n", arr_list) out_array = np.atleast_1d(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]] |