🌐
NumPy
numpy.org › doc › 2.4 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.4 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.2 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.5 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.1 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-asarray-in-python
numpy.asarray() in Python - GeeksforGeeks
November 12, 2021 - numpy.asarray()function is used when we want to convert input to an array.
🌐
NumPy
numpy.org › doc › 1.25 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v1.25 Manual
numpy.asarray(a, dtype=None, order=None, *, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.6.dev0 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.0 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
NumPy
numpy.org › doc › 1.26 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v1.26 Manual
numpy.asarray(a, dtype=None, order=None, *, like=None)# Convert the input to an array. Parameters: aarray_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.
Find elsewhere
🌐
Programiz
programiz.com › python-programming › numpy › methods › asarray
NumPy asarray()
The asarray() method converts all array_like objects into an array. import numpy as np # create array-like objects list1 = [1, 2, 3, 4, 5] tuple1 = (1, 2, 3, 4, 5) # convert them to arrays array1 = np.asarray(list1) array2 = np.asarray(tuple1) print(array1) print(array2) ''' Output: [1 2 3 ...
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v2.3 Manual
numpy.asarray(a, dtype=None, order=None, *, device=None, copy=None, like=None)# Convert the input to an array. Parameters: aarray_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.
🌐
w3resource
w3resource.com › numpy › manipulation › asarray.php
NumPy: numpy.asarray() function - w3resource
March 24, 2023 - The numpy.asarray() function is used to convert n given input to an array.
Top answer
1 of 8
335

The definition of asarray is:

def asarray(a, dtype=None, order=None):
    return array(a, dtype, copy=False, order=order)

So it is like array, except it has fewer options, and copy=False. array has copy=True by default.

The main difference is that array (by default) will make a copy of the object, while asarray will not unless necessary.

2 of 8
240

Since other questions are being redirected to this one which ask about asanyarray or other array creation routines, it's probably worth having a brief summary of what each of them does.

The differences are mainly about when to return the input unchanged, as opposed to making a new array as a copy.

array offers a wide variety of options (most of the other functions are thin wrappers around it), including flags to determine when to copy. A full explanation would take just as long as the docs (see Array Creation, but briefly, here are some examples:

Assume a is an ndarray, and m is a matrix, and they both have a dtype of float32:

  • np.array(a) and np.array(m) will copy both, because that's the default behavior.
  • np.array(a, copy=False) and np.array(m, copy=False) will copy m but not a, because m is not an ndarray.
  • np.array(a, copy=False, subok=True) and np.array(m, copy=False, subok=True) will copy neither, because m is a matrix, which is a subclass of ndarray.
  • np.array(a, dtype=int, copy=False, subok=True) will copy both, because the dtype is not compatible.

Most of the other functions are thin wrappers around array that control when copying happens:

  • asarray: The input will be returned uncopied iff it's a compatible ndarray (copy=False).
  • asanyarray: The input will be returned uncopied iff it's a compatible ndarray or subclass like matrix (copy=False, subok=True).
  • ascontiguousarray: The input will be returned uncopied iff it's a compatible ndarray in contiguous C order (copy=False, order='C').
  • asfortranarray: The input will be returned uncopied iff it's a compatible ndarray in contiguous Fortran order (copy=False, order='F').
  • require: The input will be returned uncopied iff it's compatible with the specified requirements string.
  • copy: The input is always copied.
  • fromiter: The input is treated as an iterable (so, e.g., you can construct an array from an iterator's elements, instead of an object array with the iterator); always copied.

There are also convenience functions, like asarray_chkfinite (same copying rules as asarray, but raises ValueError if there are any nan or inf values), and constructors for subclasses like matrix or for special cases like record arrays, and of course the actual ndarray constructor (which lets you create an array directly out of strides over a buffer).

🌐
NumPy
numpy.org › doc › 1.18 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v1.18 Manual
numpy.asarray(a, dtype=None, order=None)[source]¶ · Convert the input to an array. Parameters · aarray_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.
🌐
NumPy
numpy.org › doc › 1.16 › reference › generated › numpy.asarray.html
numpy.asarray — NumPy v1.16 Manual
>>> a = np.array([1, 2], dtype=np.float32) >>> np.asarray(a, dtype=np.float32) is a True >>> np.asarray(a, dtype=np.float64) is a False
🌐
LabEx
labex.io › tutorials › numpy-asarray-function-86404
NumPy Asarray Function | LabEx
The numpy.asarray() function is used to convert the input data into a NumPy array object. The function can accept any existing data like Lists, Tuples, and ndarrays and convert it into an array.
🌐
Python Pool
pythonpool.com › home › numpy › numpy asarray(): convert data without unnecessary copies
NumPy asarray(): Convert Data Without Unnecessary Copies
July 13, 2026 - Use np.asarray(value) at the boundary of a numerical function when the function needs an ndarray but should avoid an unnecessary copy. Pass dtype when the calculation requires a specific data type. Remember that the returned array can share memory with an existing compatible ndarray, so mutating it may mutate the caller's data. The official numpy.asarray reference documents conversion, dtype, order, and copy behavior.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_asarray_function.htm
Numpy asarray() Function
The numpy.asarray() function can create an N-dimensional array by passing multiple sequences, such as lists or tuples, of the same size.
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › asarray()
Python Numpy asarray() - Convert to Array
November 8, 2024 - The numpy.asarray() function in Python is an integral part of the Numpy library, used extensively for converting various input data types like lists, tuples, and other array-like objects into a Numpy ndarray.