Replies: 4 comments 5 replies
-
Import the tensorprint from tensorutil to print the tensor. from tensorutils import tensorprint t = rand[type](2, 3,3) tensorprint(t) OR You can iterate through it and check what's in it. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Here's an example of how to interpret a Mojo def func(tensor: Tensor[DType.int32])
np = Python.import_module("numpy")
ctypeslib = Python.import_module("numpy.ctypeslib")
ctypes = Python.import_module("ctypes")
var rows = tensor.shape()[0]
var cols = tensor.shape()[1]
data_ptr = ctypes.cast(int(tensor._ptr), ctypes.POINTER(ctypes.c_int32))
numpy_array = ctypeslib.as_array(data_ptr, shape=(rows, cols))
# numpy_array now contains the tensor's content, no traversal required! |
Beta Was this translation helpful? Give feedback.
-
Basalt has some utilities for that as well: |
Beta Was this translation helpful? Give feedback.
-
I created a Tensor object, and applied some operations. but now I don't know how can I view the tensor? or if possible can I convert it to numpy array so that I can apply some python function?
Beta Was this translation helpful? Give feedback.
All reactions