array<T extends SizedNativeType> function

VARP array<T extends SizedNativeType>(
  1. dynamic a, {
  2. String order = "K",
  3. bool copy = true,
  4. int ndim = 0,
})

array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0, like=None) Create an array.

Parameters

object : var_like An var, any object exposing the var interface, an object whose array method returns an array, or any (nested) sequence. If object is a scalar, a 0-dimensional array containing object is returned. dtype : data-type, optional The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. copy : bool, optional If true (default), then the object is copied. Otherwise, a copy will only be made if array returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). order : {'C', 'F', 'A', 'K'}, optional Compatible with numpy. subok : bool, optional Compatible with numpy. ndmin : int, optional Specifies the minimum number of dimensions that the resulting array should have. Ones will be pre-pended to the shape as needed to meet this requirement. like : var_like Compatible with numpy.

Returns

out : var An var object satisfying the specified requirements.

Examples

np.array(1, 2, 3) var(1, 2, 3) np.array([1, 2, 3, 4]) var([1, 2, 3, 4])

Implementation

VARP array<T extends ffi.SizedNativeType>(
  dynamic a, {
  String order = "K",
  bool copy = true,
  int ndim = 0,
}) {
  _orderAssert(order);
  VARP x;
  if (a is VARP) {
    x = F.clone(a, deepCopy: copy);
  } else {
    x = _toVARP<T>(a);
  }
  x = F.cast<T>(x);
  if (ndim > 0 && x.ndim != null) {
    final dim = x.ndim!;
    if (ndim > dim) {
      x = F.unsqueeze(x, axis: List.generate(ndim - dim, (index) => index));
    }
  }
  return x;
}