# [Numpy-discussion] Conservative order in .argsort

Berthold Höllmann berthold.hoellmann@gl-group....
Fri Mar 9 02:37:53 CST 2007

```In our process of switching from Numeric to numpy we had a problem
with a function using argsort. The function expected a conservative
order of the argsort result but we got:

>>> import numpy
>>> numpy.argsort(numpy.ones(16, dtype=numpy.dtype('float64')))
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])
>>> numpy.argsort(numpy.ones(17, dtype=numpy.dtype('float64')))
array([ 0, 14, 13, 12, 11, 10,  9, 15,  8,  6,  5,  4,  3,  2,  1,  7, 16])
>>> numpy.ones(17, dtype=numpy.dtype('float64')).argsort()
array([ 0, 14, 13, 12, 11, 10,  9, 15,  8,  6,  5,  4,  3,  2,  1,  7, 16])
>>> numpy.ones(17, dtype=numpy.dtype('float64')).argsort(kind='heap')
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,  0])
>>> numpy.ones(17, dtype=numpy.dtype('float64')).argsort(kind='merge')
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16])
>>> numpy.ones(100, dtype=numpy.dtype('float64')).argsort(kind='merge')
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])

My question is, is "kind='merge'" sorting garanteed to be conservative?

Kind regards

Berthold Höllmann
--
Germanischer Lloyd AG
CAE Development
Vorsetzen 35
20459 Hamburg
Phone: +49(0)40 36149-7374
Fax: +49(0)40 36149-7320
e-mail: berthold.hoellmann@gl-group.com
Internet: http://www.gl-group.com

This e-mail and any attachment thereto may contain confidential information and/or information protected by intellectual property rights for the exclusive attention of the intended addressees named above. Any access of third parties to this e-mail is unauthorised. Any use of this e-mail by unintended recipients such as total or partial copying, distribution, disclosure etc. is prohibited and may be unlawful. When addressed to our clients the content of this e-mail is subject to the General Terms and Conditions of GL's Group of Companies applicable at the date of this e-mail.

If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer.

GL's Group of Companies does not warrant and/or guarantee that this message at the moment of receipt is authentic, correct and its communication free of errors, interruption etc.

Germanischer Lloyd AG, 31393 AG HH, Hamburg, Vorstand: Dr. Hermann J. Klein, Rainer Schöndube, Vorsitzender des Aufsichtsrats: Dr. Wolfgang Peiner
```