How to convert array to numpy array with numpy.asarray() function

Spread the love

In this article, you will learn how to convert array to numpy array with numpy.asarray() function.

Syntax: numpy.asarray(a, dtype=None, order=None)
Convert the input to an array.

Parameters:
a : array_like
Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.

dtype : data-type, optional
By default, the data-type is inferred from the input data.

order : {‘C’, ‘F’}, optional
Whether to use row-major (C-style) or column-major (Fortran-style) memory representation. Defaults to ‘C’.

Returns:
out : ndarray
Array interpretation of a. No copy is performed if the input is already an ndarray with matching dtype and order. If a is a subclass of ndarray, a base class ndarray is returned.

import numpy as np a = [1, 2,3,4] print(type(a)) a=np.asarray(a) print(type(a))

Output:

[1, 2, 3, 4]

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *