# qcircuits.tensors module¶

class qcircuits.tensors.Tensor(tensor)

Bases: object

A container class for a tensor representing either a state vector or an operator, with methods for common functionality of both State and Operator.

Parameters: tensor (numpy complex128 multidimensional array) – The tensor representing either a quantum state or an operator on the vector space for a quantum state.
rank

Get the rank of the tensor. For d qubit systems, a State will have rank d, while an Operator with have rank 2d

Returns: The tensor rank. int
shape

Get the shape of the tensor. For d qubit systems, a State will have shape [2] $$\times d$$, while an Operator will have shape [2] $$\times 2d$$.

Returns: The tensor shape. int
tensor_power(n)

Return the State or Operator given by the tensor product of this object with itself n times. Can also be called with the infix ** operator, i.e., A**n.

Parameters: n (int) – The number of times to take the tensor product of this object with itself. If this object has tensor A, returns $$A^{\otimes n}$$. State or Operator (depends on this object type)
tensor_product(arg)

Return the State or Operator given by the tensor product of this object with another State or Operator. Can also be called with the infix * operator, i.e., A * B.

Parameters: arg (State) – The State or Operator with which to take the tensor product. If this object has tensor A, and argument has tensor B, returns $$A\otimes B$$. State or Operator (depends on argument type)