> For the complete documentation index, see [llms.txt](https://openvector.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openvector.gitbook.io/docs/python-api-references/tensor.md).

# Tensor

* `cofhe.Tensor`\
  The core tensor class in CoFHE, similar to `torch.Tensor`, but with additional support for encrypted computations. It supports tensor operations such as addition, multiplication, and broadcasting, while maintaining privacy for the underlying data.
* `Tensor.new_tensor(data)`\
  Creates a new tensor from the provided data, preserving the encryption format if applicable.
* `Tensor.new_empty(shape)`\
  Creates a new tensor filled with uninitialized values, with the specified shape.
* `Tensor.new_zeros(shape)`\
  Creates a new tensor filled with zeros of the specified shape.
* `Tensor.new_ones(shape)`\
  Creates a new tensor filled with ones of the specified shape.
* `Tensor.new_full(shape, fill_value)`\
  Creates a new tensor with the specified shape and fills it with the provided value.
* `Tensor.new_rand(shape)`\
  Creates a new tensor with random values between 0 and 1.
* `Tensor.new_randn(shape)`\
  Creates a new tensor filled with values sampled from a standard normal distribution.
* `Tensor.new_eye(size)`\
  Creates a new identity matrix (diagonal of ones, other elements are zeros) with the specified size.
* `Tensor.new_arange(start, end, step)`\
  Creates a tensor filled with values from `start` to `end` with the given step size.
* `Tensor.new_linspace(start, end, steps)`\
  Creates a tensor with linearly spaced values from `start` to `end`, having `steps` number of points.
* `Tensor.new_logspace(start, end, steps)`\
  Creates a tensor with logarithmically spaced values between 10^start and 10^end, with `steps` points.
* `Tensor.element_size()`\
  Returns the size (in bytes) of each element in the tensor.
* `Tensor.numel()`\
  Returns the total number of elements in the tensor.
* `Tensor.size()`\
  Returns the shape of the tensor.
* `Tensor.shape()`\
  Returns the shape (tuple of dimensions) of the tensor.
* `Tensor.dim()`\
  Returns the number of dimensions (rank) of the tensor.
* `Tensor.view(new_shape)`\
  Returns a new tensor with the same data but a different shape.
* `Tensor.reshape(new_shape)`\
  Returns a new tensor with the same data but with a reshaped dimension.
* `Tensor.squeeze(dim)`\
  Removes the specified dimension (if its size is 1) from the tensor.
* `Tensor.unsqueeze(dim)`\
  Adds a dimension of size 1 at the specified position.
* `Tensor.flatten()`\
  Flattens the tensor into a 1D tensor.
* `Tensor.transpose(dim0, dim1)`\
  Transposes two dimensions of the tensor.
* `Tensor.t()`\
  Returns the transpose of the tensor (works only on 2D tensors).
* `Tensor.contiguous()`\
  Returns a contiguous tensor in memory (useful after operations like transpose or reshape).
* `Tensor.clone()`\
  Returns a copy of the tensor, maintaining the original's encryption state.
