numpy.atleast_3d() in Python
The numpy.atleast_3d() function views the inputs as arrays with at least three dimensions.
Syntax
numpy.atleast_3d(*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, or list of arrays, each with a.ndim >= 3.
Example 1
# Python Program explaining
# numpy.atleast_3d() function
import numpy as np
int_num = 100
print ("Input number: \n", int_num)
out_array = np.atleast_3d(int_num)
print ("\n Output 3d array: \n", out_array)
Output
Input number:
100
Output 3d array:
[[[100]]]
Example 2
# Python Program explaining
# numpy.atleast_3d() function
import numpy as np
arr_list = [[22, 76, 60],
[85, 192, 6]]
print ("Input list: \n", arr_list)
out_array = np.atleast_3d(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]]]