MCPcopy
hub / github.com/dask/dask / asarray

Function asarray

dask/array/_array_expr/_collection.py:1205–1280  ·  view source on GitHub ↗

Convert the input to a dask array. Parameters ---------- a : array-like Input data, in any form that can be converted to a dask array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. allow_unknown_chunksizes: bool

(
    a, allow_unknown_chunksizes=False, dtype=None, order=None, *, like=None, **kwargs
)

Source from the content-addressed store, hash-verified

1203
1204
1205def asarray(
1206 a, allow_unknown_chunksizes=False, dtype=None, order=None, *, like=None, **kwargs
1207):
1208 """Convert the input to a dask array.
1209
1210 Parameters
1211 ----------
1212 a : array-like
1213 Input data, in any form that can be converted to a dask array. This
1214 includes lists, lists of tuples, tuples, tuples of tuples, tuples of
1215 lists and ndarrays.
1216 allow_unknown_chunksizes: bool
1217 Allow unknown chunksizes, such as come from converting from dask
1218 dataframes. Dask.array is unable to verify that chunks line up. If
1219 data comes from differently aligned sources then this can cause
1220 unexpected results.
1221 dtype : data-type, optional
1222 By default, the data-type is inferred from the input data.
1223 order : {‘C’, ‘F’, ‘A’, ‘K’}, optional
1224 Memory layout. ‘A’ and ‘K’ depend on the order of input array a.
1225 ‘C’ row-major (C-style), ‘F’ column-major (Fortran-style) memory
1226 representation. ‘A’ (any) means ‘F’ if a is Fortran contiguous, ‘C’
1227 otherwise ‘K’ (keep) preserve input order. Defaults to ‘C’.
1228 like: array-like
1229 Reference object to allow the creation of Dask arrays with chunks
1230 that are not NumPy arrays. If an array-like passed in as ``like``
1231 supports the ``__array_function__`` protocol, the chunk type of the
1232 resulting array will be defined by it. In this case, it ensures the
1233 creation of a Dask array compatible with that passed in via this
1234 argument. If ``like`` is a Dask array, the chunk type of the
1235 resulting array will be defined by the chunk type of ``like``.
1236 Requires NumPy 1.20.0 or higher.
1237
1238 Returns
1239 -------
1240 out : dask array
1241 Dask array interpretation of a.
1242
1243 Examples
1244 --------
1245 >>> import dask.array as da
1246 >>> import numpy as np
1247 >>> x = np.arange(3)
1248 >>> da.asarray(x)
1249 dask.array<array, shape=(3,), dtype=int64, chunksize=(3,), chunktype=numpy.ndarray>
1250
1251 >>> y = [[1, 2, 3], [4, 5, 6]]
1252 >>> da.asarray(y)
1253 dask.array<array, shape=(2, 3), dtype=int64, chunksize=(2, 3), chunktype=numpy.ndarray>
1254
1255 .. warning::
1256 `order` is ignored if `a` is an `Array`, has the attribute ``to_dask_array``,
1257 or is a list or tuple of `Array`&#x27;s.
1258 """
1259 if like is None:
1260 if isinstance(a, Array):
1261 return _as_dtype(a, dtype)
1262 elif hasattr(a, "to_dask_array"):

Callers 15

apply_gufuncFunction · 0.90
outerMethod · 0.90
empty_likeFunction · 0.90
ones_likeFunction · 0.90
zeros_likeFunction · 0.90
full_likeFunction · 0.90
asanyarrayFunction · 0.70
stackFunction · 0.70
arrayFunction · 0.70
concatenateFunction · 0.70
test_numpy_asarray_dtypeFunction · 0.50

Calls 8

anyFunction · 0.90
meta_from_arrayFunction · 0.90
to_dask_arrayMethod · 0.80
splitMethod · 0.80
_as_dtypeFunction · 0.70
stackFunction · 0.70
from_arrayFunction · 0.70
map_blocksMethod · 0.45

Tested by 11

test_numpy_asarray_dtypeFunction · 0.40
test_asarrayFunction · 0.40
test_asarray_array_dtypeFunction · 0.40
test_asarray_h5pyFunction · 0.40
test_ravel_multi_indexFunction · 0.40
test_meta_from_arrayFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…