numpy.atleast_1d() in Python
The numpy.atleast_1d() function converts the inputs to arrays with at least one dimension.
Syntax
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
# 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
Input number:
100
output 1d array:
[100]
Example 2
# 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
Input list:
[[22, 76, 60], [85, 192, 6]]
Output array:
[[ 22 76 60]
[ 85 192 6]]