Display a matrix

Hello,

I have a function which defines a stress tensor. I would like to print the values of sigma matrix inside the function. Here is the sample of the code.

    def stress():
    	
    	Fm   =  as_tensor([[1, 0], [0, 1]])
    	B_   =  dot(Fm,Fm.T)
    	vol  =  c * (B_ - tr(B_)/2.*Identity(2))

    	sigma = vol

    	return sigma

Thank you.

Assuming c is just a number or something simple you can cast the components of the tensor to a float. E.g.

print(float(sigma[0,0]))

bear in mind, that if your tensor is composed of symbolic quantities representing fields, then of course it’s no longer possible to interpret that quantity as a single real number.

1 Like

Thank you very much. It works