Create and modify tensors
Tensor methods in Sentis are similar to methods in frameworks like numpy, TensorFlow, and PyTorch.
Create a basic tensor
Create a basic tensor using the methods in the TensorFloat
or TensorInt
APIs. For example use TensorFloat.Zeros
to create a tensor filled with 0
.
Refer to Create input for a model for more information.
Reshape a tensor
You can't change the shape of a tensor, but you can use ShallowReshape
to create a reshaped copy of a tensor.
For example:
TensorShape shape = new TensorShape(2, 2, 2);
int[] data = new int[] { 1, 2, 3, 4, 10, 20, 30, 40 };
TensorInt tensor = new TensorInt(shape, data);
TensorShape newShape = new TensorShape(2, 1, 4);
Tensor reshapedTensor = tensor.ShallowReshape(newShape);
The shape of the tensor and the new shape must have the same number of elements. You can use the length
property of a tensor to check the number of elements.
The result of ShallowReshape
is a shallow copy that points to the same memory as the original output.
Don't use ShallowReshape
if you use BackendType.GPUPixel
, because ShallowReshape
isn't compatible with the way Sentis stores tensor data in textures.
Additional resources
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.