Methods for ndarray

Source: Internet
Author: User

Methods for ndarray

 

 

Use help in Python

>>> Import numpy
>>> Help (numpy. argsort)

 

Argsort function usage: (numpy-ref-1.8.1P1240)

Argsort (a, axis =-1, kind = 'quicksort ', order = None)
Returns the indices that wowould sort an array.

The argsort function returns an index value from small to large.

#######################################

Examples
--------
One dimen1_array: One-dimensional array
>>> X = np. array ([3, 1, 2])
>>> Np. argsort (x)
Array ([1, 2, 0])

Two-dimen1_array: Two-dimensional array
>>> X = np. array ([[0, 3], [2, 2])
>>> X
Array ([[0, 3],
[2, 2])
>>> Np. argsort (x, axis = 0) # sort by Column
Array ([[0, 1],
[1, 0])
>>> Np. argsort (x, axis = 1) # sort by row
Array ([[0, 1],
[0, 1])


>>> X = np. array ([3, 1, 2])
>>> Np. argsort (x) # sort in ascending order
Array ([1, 2, 0])
>>> Np. argsort (-x) # sort by descending order
Array ([0, 2, 1])

Another method is to sort data in descending order:

>>> A = x [np. argsort (x)]
>>>
Array ([1, 2, 3])
>>> A [:-1]
Array ([3, 2, 1])


>>> X [np. argsort (x)] # array sorted by index value
Array ([1, 2, 3])
>>> X [np. argsort (-x)]
Array ([3, 2, 1])

From: http://blog.csdn.net/pipisorry/article/details/41214819

Ref:

Argsort function usage in numpy

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.