Marceline
Marceline

Reputation: 1

How to solve the incompatible object shape error in python

I'm writing this code on python but it is giving the error of incompatibility so matrix multiplication cannot take place and hence data cannot be plotted.

# !pip3 install qutip
import qutip as qt
import matplotlib.pyplot as plt
import numpy as np
ω = qt.Qobj(np.arange(0.0,1.1,0.1))
Δ=o=0.1
ℏ=1.05457182*10**(-34)
σx = qt.sigmax()
σy = qt.sigmay()
σz = qt.sigmaz()
H = ℏ*(Δ*σx + o*σy + ω*σz)/2
plt.plot(ω,H)
plt.show()

....

TypeError: Incompatible Qobj shapes.

Code failed because the ω variable was a Qobj with dimensions [[2], [1]], while the Pauli matrices σx, σy, and σz had dimensions [[2, 2]]. This resulted in a shape mismatch when performing the matrix multiplication in the Hamiltonian definition. so how to create w with above range having shape[[2],[2]]

Upvotes: 0

Views: 62

Answers (0)

Related Questions