docarray.math.ndarray module#
- docarray.math.ndarray.ravel(value, docs, field)[source]#
Ravel
value
intodoc.field
of each documents- Parameters:
docs (DocumentArray) – the docs to set
field (
str
) – the field of the doc to setvalue (ArrayType) – the value to be set on
doc.field
- Return type:
None
- docarray.math.ndarray.get_array_type(array, raise_error_if_not_array=True)[source]#
Get the type of ndarray without importing the framework
- Parameters:
array (ArrayType) – any array, scipy, numpy, tf, torch, etc.
- Return type:
Tuple
[str
,bool
]- Returns:
a tuple where the first element represents the framework, the second represents if it is sparse array
- docarray.math.ndarray.to_numpy_array(value)[source]#
Return the value always in
numpy.ndarray
regardless the framework type.- Return type:
ndarray
- Returns:
the value in
numpy.ndarray
.
- docarray.math.ndarray.get_array_rows(array)[source]#
Get the number of rows of the ndarray without importing all frameworks
- Parameters:
array (ArrayType) – input array
- Return type:
Tuple
[int
,int
]- Returns:
(num_rows, ndim)
Examples
>>> get_array_rows([1,2,3]) 1, 1 >>> get_array_rows([[1,2,3], [4,5,6]]) 2, 2 >>> get_array_rows([[1,2,3], [4,5,6], [7,8,9]]) 3, 2 >>> get_array_rows(np.array([[1,2,3], [4,5,6], [7,8,9]])) 3, 2
- docarray.math.ndarray.check_arraylike_equality(x, y)[source]#
Check if two array type objects are the same with the supported frameworks.
Examples
>>> import numpy as np x = np.array([[1,2,0,0,3],[1,2,0,0,3]]) check_arraylike_equality(x,x) True
>>> from scipy import sparse as sp x = sp.csr_matrix([[1,2,0,0,3],[1,2,0,0,3]]) check_arraylike_equality(x,x) True
>>> import torch x = torch.tensor([1,2,3]) check_arraylike_equality(x,x) True