I am having a lot of trouble sorting an array. The array contains 140 inner arrays of 3 points (x y z). I would like to sort all arrays based on lowest x coordinate to the highest. I have googled many methods and none of them have worked so far.
The sort() method takes optional arguments for controlling the comparisons.
cmp specifies a custom comparison function of two arguments (list items) which should return a negative, zero or positive number depending on whether the first argument is considered smaller than, equal to, or larger than the second argument: cmp=lambda x,y: cmp(x.lower(), y.lower()). The default value is None.
key specifies a function of one argument that is used to extract a comparison key from each list element: key=str.lower. The default value is None.
reverse is a boolean value. If set to True, then the list elements are sorted as if each comparison were reversed.
In general, the key and reverse conversion processes are much faster than specifying an equivalent cmp function. This is because cmp is called multiple times for each list element while key and reverse touch each element only once.
Changed in version 2.3: Support for None as an equivalent to omitting cmp was added.
Changed in version 2.4: Support for key and reverse was added
cmp is an invalid keyword argument for this function
I agree. I read the same thing. The two suggestions you have supplied are what I have been trying. I do not know how to make it work since it is always coming back with error. The only time I have had anything work is when I use x.sort(0) in which it sorted all information from lowest to highest in all columns. Anything else has left the array exactly the same as how it was entered.
Error: The truth value of an array with more than one value is ambiguous. Please use a.any() or a.all()
I noticed that everyone is putting commas. There are none in my array and i can't change that (predetermined data)... is there something different I have to do? I've noticed details often make a big difference...