abracudabra.conversion.carray ============================= .. py:module:: abracudabra.conversion.carray .. autoapi-nested-parse:: Convert to numpy or cupy arrays. Functions --------- .. autoapisummary:: abracudabra.conversion.carray.to_array Module Contents --------------- .. py:function:: to_array(sequence, /, device = None, *, strict = False) Convert an array, series, or dataframe to a NumPy or CuPy array. :param sequence: The sequence to convert. :param device: The device to convert the sequence to. If None, the sequence stays on the same device. :param strict: Whether to raise an error if the sequence is not a valid type. A NumPy/CuPy array, Pandas/cuDF series or dataframe, or Torch tensor are valid types. If False, the sequence is converted to a NumPy/CuPy array if possible, but it might raise an error if the conversion is not possible. :returns: A NumPy/CuPy array. :raises TypeError: If the sequence is not a valid type and ``strict`` is True. .. rubric:: Examples Build a CuPy array from a sequence >>> import cupy as cp >>> cupy_array = to_array([1, 2, 3], "cuda:0") >>> print(type(cupy_array)) Build a NumPy array from a cuDF series >>> import cudf >>> cudf_series = cudf.Series([1, 2, 3]) >>> numpy_array = to_array(cudf_series) >>> print(type(numpy_array))