module
tensor
Implements the Tensor
type.
Example:
from tensor import Tensor, TensorSpec, TensorShape
from utils.index import Index
var height = 256
var width = 256
var channels = 3
# Create the tensor of dimensions height, width, channels
# and fill with random values.
var image = Tensor.rand[DType.float32](TensorShape(height, width, channels))
# Declare the grayscale image.
var spec = TensorSpec(DType.float32, height, width)
var gray_scale_image = Tensor[DType.float32](spec)
# Perform the RGB to grayscale transform.
for y in range(height):
for x in range(width):
var r = image[y,x,0]
var g = image[y,x,1]
var b = image[y,x,2]
gray_scale_image[Index(y,x)] = 0.299 * r + 0.587 * g + 0.114 * b
print(gray_scale_image.shape())
Structs
-
Tensor
: A tensor type which owns its underlying data and is parameterized on DType.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
If you'd like to share more information, please report an issue on GitHub
😔 What went wrong?