docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Create and modify tensors

    Tensor methods in Sentis are similar to methods found 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.AllocZeros to create a tensor filled with 0. Or TensorFloat.AllocNoData for a tensor with no underlying backend data.

    Refer to Create input for a model for more information.

    Reshape a tensor

    You can reshape a tensor directly, for example:

    TensorFloat tensor = TensorFloat.AllocZeros(new TensorShape(10));
    tensor.Reshape(new TensorShape(5, 2));
    

    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 shape to check the number of elements.

    Note

    If you use BackendType.GPUPixel, tensors aren't stored in a linear format. You will not be able to reshape a tensor if the data is on the GPU.

    Additional resources

    • Tensor fundamentals
    • Model inputs
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)