Answers for "numpy sort"

2

numpy sort

>>> a = np.array([[1,4],[3,1]])
>>> np.sort(a)                # sort along the last axis
array([[1, 4],
       [1, 3]])
>>> np.sort(a, axis=None)     # sort the flattened array
array([1, 1, 3, 4])
>>> np.sort(a, axis=0)        # sort along the first axis
array([[1, 1],
       [3, 4]])
Posted by: Guest on May-22-2020
0

sort numpy array

import numpy as np

arr = np.array([3, 2, 0, 1])

print(np.sort(arr))
Posted by: Guest on April-09-2021
0

numpy sort

import numpy as np
#original 2-dimentional array
nnl_array = np.array([[1,5,3], [6,5,7]])
print ("original array", "\n", nnl_array)
#axis=none
a_nnl_array = np.sort(nnl_array, axis=None)
print("axis=none", "\n", a_nnl_array)
#axis=-1
b_nnl_array = np.sort(nnl_array, axis=-1)
print("axis=-1", "\n", b_nnl_array)
#axis=0
c_nnl_array = np.sort(nnl_array, axis=0)
print("axis=0", "\n", c_nnl_array)
#axis=1
d_nnl_array = np.sort(nnl_array, axis=1)
print("axis=1", "\n", d_nnl_array)
Posted by: Guest on August-28-2021
0

sort numpy array

import numpy as np

arr = np.array(['banana', 'cherry', 'apple'])

print(np.sort(arr))
Posted by: Guest on April-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language