×

numpy.atleast_2d() in Python

numpy.atleast_2d() in Python

The numpy.atleast_2d() function converts the inputs as arrays with at least two dimensions.

Syntax

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

# 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

Input  number:
100
Output 2d array:
[[100]]

Example 2

# 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

Input  list:
[[22, 76, 60], [85, 192, 6]]
Output Array:
[[ 22  76  60]
[ 85 192   6]]

Related Topics

numpy.atleast_3d() in Python

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...

1 minute read.

numpy.logspace() in Python

numpy.logspace() in Python The logspace() function of Python numpy class returns the equal number of spaces over every interval on a log scale. Syntax numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0) Parameter start: It represents the start of the interval range. stop:...

1 minute read.

numpy.loadtxt() Python

Python numpy.loadtxt() The loadtxt() function of Python numpy class loads the data from a text fileand provides a fast reader for simple text files. Syntax numpy.loadtxt(fname, dtype=<class'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None) Parameter fname : This parameter represents a file, filename, or...

2 minutes read.

numpy.split() in Python

numpy.split() in Python The numpy.split() function splits an array into multiple sub-arrays. Syntax numpy.split(ary, indices_or_sections, axis=0) Parameter ary: This parameter represents the Array to be divided into sub-arrays. indices_or_sections : This parameter represents an int or an 1-D array. If indices_or_sections is an...

1 minute read.

numpy.vstack() in Python

numpy.vstack() in Python The numpy.vstack() function stacks the arrays in a sequence vertically (row wise). Syntax numpy.vstack(tup) Parameter tup: This parameter represents the sequence of ‘ndarrays’ where the arrays must have the same shape along all...

1 minute read.

numpy.tile() in Python

numpy.tile() in Python The numpy.tile() function constructs an array by repeating the parameter ‘A’  the number of times as specified by the ‘reps’ parameter. Syntax numpy.tile(A, reps) Parameter The numpy.tile() function consists of two parameters, which...

1 minute read.

Python NumPy Tutorial

NumPy is a scientific library in Python Programming Language. It provides objects and routines for fast operations on arrays, random simulations, statistical operations, sorting, etc. Numpy has an ndarray object which...

2 minutes read.

numpy.swapaxes() in Python

numpy.swapaxes() in Python The numpy.swapaxes() function interchanges the two specified axes of the given array. Syntax numpy.swapaxes(a, axis1, axis2) Parameter The numpy.swapaxes() method consists of three parameters, which are as follows: a : This parameter represents the Input array. axis1 : It represents...

1 minute read.

numpy.empty() in Python

numpy.empty() in Python The empty() method of Python numpy class returns a new array of the specified shape and type, without initializing the entries. Syntax numpy.empty(shape, dtype=float, order='C') Parameters The numpy.empty method consists of three parameters, which...

1 minute read.

numpy.resize() in Python

numpy.resize() in Python The numpy.resize() returns a new array with the specified shape. If the new array is larger than the original array, then the new array is filled with repeated...

1 minute read.

numpy.stack() in Python

numpy.stack() in Python The numpy.stack() function joins a sequence of arrays along a new axis. Syntax numpy.stack(arrays, axis=0, out=None) Parameter arrays: This parameter represents a sequence of the array where each array have the same shape. axis: It is an...

1 minute read.

numpy.diag() in Python

numpy.diag() in Python The diag() function of Python numpy class extracts and construct a diagonal array. Syntax numpy.diag(v, k=0) Parameter a: It represents the array_like. k: It represents the diagonal value that we require. It is an...

1 minute read.

numpy.full() in Python

numpy.full() in Python The full() method of Python numpy class returns a new array of specified shape and type, filled with fill_value. Syntax numpy.full(shape, fill_value, dtype=None, order='C') Parameter shape:This parameter represents the number of rows order :The order parameter can...

1 minute read.

numpy.rollaxis() in Python

numpy.rollaxis() in Python The numpy.rollaxis() function rolls the given axis backwards until it lies in the specified position. Syntax numpy.rollaxis(a, axis, start=0) Parameter The numpy. rollaxis() method consists of three parameters, which are as follows: a : It represents an...

1 minute read.

numpy.transpose() in Python

numpy.transpose() in Python The numpy.transpose() permutes the dimensions of an array. Syntax numpy.transpose(a, axes=None) Parameter a : This parameter represents an input array. axes : It is an optional parameter which by default, reverses the dimensions, otherwise permutes the axes according...

1 minute read.

numpy.identity() in Python

numpy.identity() in Python The identity() method of Python numpy class returns an identity matrix i.e., a square matrix with ones on the main diagonal. Syntax numpy.identity(n, dtype=None) Parameters The numpy. identity()  method consists of two parameters,...

1 minute read.

numpy.column_stack() in Python

numpy.column_stack() in Python The numpy.column_stack() function stacks  the 1-D arrays as columns into a 2-D array. It takes a sequence of 1-D arrays and stacks them as columns to make a...

1 minute read.

numpy.zeros in Python

numpy.zeros in Python The zeros() method of Python numpy class returns a new array of given shape and type, filled with zeros. Syntax numpy.zeros(shape, dtype=float, order='C') Parameter The numpy.zeros() method consists of three parameters, which are as...

1 minute read.

numpy.diagflat() in Python

numpy.diagflat() in Python The diagflat() function of Python numpy class creates a two-dimensional array with the array_like input as a diagonal to the new output array. Syntax numpy.diagflat (a, k = 0) Parameter a :...

1 minute read.

numpy.expand_dims() in Python

numpy.expand_dims() in Python The numpy.expand_dims() function expands the shape of an array. It Inserts a new axis that appears at the axis position in the expanded array shape. Syntax numpy.expand_dims(a, axis) Parameter The numpy.expand_dims() function has two parameters...

1 minute read.