How to align principal axes of 3D density map in numpy with Cartesian axes?
问题 I have an n x n x n numpy array that contains density values on a cubic grid. I'm trying to align the principal axes of inertia of the density map with the cartesian x,y,z axes of the grid. I have the following so far: import numpy as np from scipy import ndimage def center_rho(rho): """Move density map so its center of mass aligns with the center of the grid""" rhocom = np.array(ndimage.measurements.center_of_mass(rho)) gridcenter = np.array(rho.shape)/2. shift = gridcenter-rhocom rho =