I have an N x 100 numpy matrix containing any kind of numbers that I want to sort.
In order for it to be more visual, I will now fill it out with dummy values:
import numpy as np
X = np.array( [[float(number) for number in range(100)] for _ in range(10)] )
# X
[[ 0. 1. 2. ..., 97. 98. 99.]
[ 0. 1. 2. ..., 97. 98. 99.]
[ 0. 1. 2. ..., 97. 98. 99.]
...,
[ 0. 1. 2. ..., 97. 98. 99.]
[ 0. 1. 2. ..., 97. 98. 99.]
[ 0. 1. 2. ..., 97. 98. 99.]]
I want to sort the columns for all N rows using the following 100-element list as the key:
# s
["butterfly", "zebra", "cactus", ... "animal", "xylitol", "yoyo"]
So that the output looks like this:
# X_sorted
[[ 97. 0. 2. ..., 98. 99. 1.]
[ 97. 0. 2. ..., 98. 99. 1.]
[ 97. 0. 2. ..., 98. 99. 1.]
...,
[ 97. 0. 2. ..., 98. 99. 1.]
[ 97. 0. 2. ..., 98. 99. 1.]
[ 97. 0. 2. ..., 98. 99. 1.]]
So basically, I want to retrieve the alphabetical sorting output of s, and apply it to the columns of X.
How can I achieve this?
I am familiar with the sort command using key, but I do not know how to apply this to the matrix columns in this scenario.
Xis a numpy matrix, andsis a list. I am quite new to Python, so please let me know how to change the displayed formatting in my question in order to avoid confusion, in case they are displayed in a wrong manner.np.array(orarray(at the beginning of an array to indicate that it is an array (and of course a matching)at the end).