numpy array to permutation matrix
问题 np.array([1,2,3]) I've got numpy array. I would like to turn it into a numpy array with tuples of each 1:1 permutation. Like this: np.array([ [(1,1),(1,2),(1,3)], [(2,1),(2,2),(2,3)], [(3,1),(3,2),(3,3)], ]) Any thoughts on how to do this efficiently? I need to do this operation a few million times. 回答1: If you're working with numpy, don't work with tuples. Use its power and add another dimension of size two. My recommendation is: x = np.array([1,2,3]) np.vstack(([np.vstack((x, x, x))], [np