×

numpy.atleast_1d() in Python

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

Related Topics

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.atleast_1d() in Python

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

1 minute read.

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

1 minute read.

Numpy Attributes

Numpy Attributes The Numpy collections give attributes to the numpy arrays. These attributes assist us with knowing the shape, aspect, and different properties of a given numpy array. As we know,...

4 minutes read.

numpy.tril() in Python

numpy.tril() in Python The tril() function of Python numpy class returns a copy of an array with the elements above the k-th diagonal zeroed. Syntax numpy.tril(m, k=0) Parameter a: It represents the input array k: This parameter represents...

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 vs SciPy

NumPy- NumPy is the most important Python package for scientific computing. It's a Python library that includes a multidimensional array object, derived objects (like masked arrays and matrices), and a...

3 minutes read.

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.repeat() in Python

numpy.repeat() in Python The numpy.repeat() function repeats the elements of an array. Syntax numpy.repeat(a, repeats, axis=None) Parameter The numpy.repeat() function consists of three parameters, which are as follows: a: This parameter represents the input array. repeats: This parameter represents the...

1 minute read.

Numpy.copy() in Python with Example

Numpy.copy() in Python The copy() function of Python numpy class returns an array copy for the given object. Syntax numpy.copy(a, order='K') Parameter a: It represent the array_like input data. order :  This parameter controls the memory layout of...

1 minute read.

numpy.delete() in Python

numpy.delete() in Python The numpy.delete() function returns a new array with sub-arrays along an axis deleted. For 1-D array, this function returns those entries which are not returned by arr[obj]. Syntax numpy.delete(arr, obj, axis=None) Parameter arr: This parameter returns...

2 minutes read.

numpy.squeeze() in Python

numpy.squeeze() in Python The numpy.squeeze() function removes single-dimensional entries from the shape of an array. Syntax numpy.squeeze(a, axis=None) Parameter The numpy.squeeze() function has three parameters which are as follows: a: It represents the Input data. axis: This parameter signifies an int or...

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.ones_like() in Python

numpy.ones_like() in Python The one_like() method of Python numpy class returns an array of ones with the same shape and type as the specified array. Syntax numpy.ones_like(a, dtype=None, order='K', subok=True) Parameter The numpy.ones_like() method consists of four parameters,...

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.

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.ones() in Python

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

1 minute read.

numpy.ndarray.flat() in Python

numpy.ndarray.flat() in Python The numpy.ndarray.flat() returns a 1-D iterator over the array. This function is not a subclass of, Python’s built-in iterator object, otherwise it will act the same as a...

1 minute read.

numpy.tri() in Python

numpy.tri() in Python The tri() function of Python numpy class returns an array with ones at and below the given diagonal(k value) and zeros elsewhere. Syntax numpy.tri(N, M=None, k=0, dtype=<class 'float'>) Parameter R : It represents the number...

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