The atleast_2d()
function in Python is used to convert inputs to a given array(s) which has at least two dimensions.
Let's view the syntax of the method.
numpy.atleast_2d(*arys)
The atleast_2d()
function takes one or more input arrays, arys
.
The atleast_2d()
function returns an array with a.ndim
>= 2
.
Let's view the code for this method.
import numpy as np# creating the input valuesa = np.arange(8).reshape(2,4)# converting the input values to an arraymyarray = np.atleast_2d(a)print(myarray)
numpy
module.x
, starting from 0
to 7
using the arange()
function and having a shape of 2
rows and 4
columns.atleast_2d()
function and passed the x
variable as its argument. The result is assigned to a variable, myarray
.myarray
.