Copy a NumPy ndarray into an owned Lucid tensor.
The returned tensor owns a copy and inherits the array's dtype according
to the canonical
NumPy → Lucid mapping (np.float32 → lucid.float32,
np.int64 → lucid.int64, etc.). Mutations do not propagate between
the source array and the result. Like tensor, this bridge uses
the active default device; use tensor(arr, device="cpu") to pin it.
Parameters
ndarraynumpy.ndarrayReturns
TensorA tensor with copied values on the active default device.
Raises
RuntimeErrorDtypeMismatch exception derives from RuntimeError; object
arrays, for example, are rejected.OverflowErroruint64 array holds a value past int64's range.Notes
Lucid has no unsigned integer dtypes, so unsigned arrays widen
losslessly to the next signed width: uint8 to int16, uint16
to int32, uint32 and uint64 to int64.
This is one of the documented H4 bridge boundaries — the only places
where Lucid is allowed to take a NumPy array as input. To move the
result onto a Metal device, chain Tensor.to:
t = lucid.from_numpy(arr).to("metal")
Examples
>>> import lucid, numpy as np
>>> arr = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
>>> t = lucid.from_numpy(arr)
>>> t.dtype
lucid.float32
>>> arr[0, 0] = 99.0 # mutate the source
>>> t[0, 0].item() # the owned copy is unchanged
1.0