Consider the following:
import dolfinx
from mpi4py import MPI
import ufl
import numpy as np
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
x = ufl.SpatialCoordinate(mesh)
constant_tensor = dolfinx.fem.Constant(
mesh, np.array([[1, 0], [2, 1]], dtype=np.float64))
variable_tensor = ufl.as_tensor([[x[0], 0], [1, 3*x[1]]])
print(constant_tensor.ufl_shape)
print(variable_tensor.ufl_shape)
print(dolfinx.fem.assemble_scalar(
dolfinx.fem.form(
ufl.inner(constant_tensor, variable_tensor)*ufl.dx)))