A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Sort following NumPy array using python programming
Q:

Sort following NumPy array using python programming

0

Sort following NumPy array

  • Case 1: Sort array by the second row
  • Case 2: Sort the array by the second column
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]])

Expected Output:

Printing Original array
[[34 43 73]
 [82 22 12]
 [53 94 66]]

Sorting Original array by second row
[[73 43 34]
 [12 22 82]
 [66 94 53]]

Sorting Original array by second column
[[82 22 12]
 [34 43 73]
 [53 94 66]]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

import numpy

print("Printing Original array")
sampleArray = numpy.array([[34,43,73],[82,22,12],[53,94,66]]) 
print (sampleArray)

sortArrayByRow = sampleArray[:,sampleArray[1,:].argsort()]
print("Sorting Original array by secoond row")
print(sortArrayByRow)

print("Sorting Original array by secoond column")
sortArrayByColumn = sampleArray[sampleArray[:,1].argsort()]
print(sortArrayByColumn)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now