MCPcopy
hub / github.com/numpy/numpy / asarray

Function asarray

numpy/ma/core.py:8626–8673  ·  view source on GitHub ↗

Convert the input to a masked array of the given data-type. No copy is performed if the input is already an `ndarray`. If `a` is a subclass of `MaskedArray`, a base class `MaskedArray` is returned. Parameters ---------- a : array_like Input data, in any form that c

(a, dtype=None, order=None)

Source from the content-addressed store, hash-verified

8624
8625
8626def asarray(a, dtype=None, order=None):
8627 """
8628 Convert the input to a masked array of the given data-type.
8629
8630 No copy is performed if the input is already an `ndarray`. If `a` is
8631 a subclass of `MaskedArray`, a base class `MaskedArray` is returned.
8632
8633 Parameters
8634 ----------
8635 a : array_like
8636 Input data, in any form that can be converted to a masked array. This
8637 includes lists, lists of tuples, tuples, tuples of tuples, tuples
8638 of lists, ndarrays and masked arrays.
8639 dtype : dtype, optional
8640 By default, the data-type is inferred from the input data.
8641 order : {'C', 'F'}, optional
8642 Whether to use row-major ('C') or column-major ('FORTRAN') memory
8643 representation. Default is 'C'.
8644
8645 Returns
8646 -------
8647 out : MaskedArray
8648 Masked array interpretation of `a`.
8649
8650 See Also
8651 --------
8652 asanyarray : Similar to `asarray`, but conserves subclasses.
8653
8654 Examples
8655 --------
8656 >>> import numpy as np
8657 >>> x = np.arange(10.).reshape(2, 5)
8658 >>> x
8659 array([[0., 1., 2., 3., 4.],
8660 [5., 6., 7., 8., 9.]])
8661 >>> np.ma.asarray(x)
8662 masked_array(
8663 data=[[0., 1., 2., 3., 4.],
8664 [5., 6., 7., 8., 9.]],
8665 mask=False,
8666 fill_value=1e+20)
8667 >>> type(np.ma.asarray(x))
8668 <class 'numpy.ma.MaskedArray'>
8669
8670 """
8671 order = order or 'C'
8672 return masked_array(a, dtype=dtype, copy=False, keep_mask=True,
8673 subok=False, order=order)
8674
8675
8676def asanyarray(a, dtype=None, order=None):

Callers 15

assert_almost_equalFunction · 0.90
doMethod · 0.90
doMethod · 0.90
test_asarrayMethod · 0.90
test_putMethod · 0.90
filledMethod · 0.70
apply_along_axisFunction · 0.70
apply_over_axesFunction · 0.70

Calls

no outgoing calls

Tested by 9

assert_almost_equalFunction · 0.72
doMethod · 0.72
doMethod · 0.72
test_asarrayMethod · 0.72
test_putMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…