简体   繁体   中英

Error:ValueError: Buffer has wrong number of dimensions (expected 1, got 2)

I wanted to call the function: emptymatrix=np.zeros((sim.data.nv,sim.data.nv))
mjp.cymj._mj_fullM(model, emptymatrix, sim.data.qM) in mujoco so that I can Convert sparse inertia matrix M into full matrix so that I can calclulate the torque but I have this error:raceback (most recent call last): File "kuka.py", line 58, in mjp.cymj._mj_fullM(sim.model,emptymatrix,sim.data.qM) File ".local/lib/python3.8/site-packages/mujoco_py/generated/wrappers.pxi", line 5061, in mujoco_py.cymj._mj_fullM
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
If someone could help me I ll be so grateful.

mujoco_py's implementation of mj_fullM expects your emptymatrix to be a vector of length nv*nv, rather than a square matrix.

See these lines from robosuite :

mass_matrix = np.ndarray(shape=(len(self.sim.data.qvel) ** 2,), dtype=np.float64, order="C")
mujoco_py.cymj._mj_fullM(self.sim.model, mass_matrix, self.sim.data.qM)
mass_matrix = np.reshape(mass_matrix, (len(self.sim.data.qvel), len(self.sim.data.qvel)))
self.mass_matrix = mass_matrix[self.qvel_index, :][:, self.qvel_index]

If you make use of the new MuJoCo python bindings ( pip install mujoco ), mujoco.mj_fullM takes the square matrix as you'd expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM