0
Follow
0
View

# jupyter program application

longnaxieye 注册会员
2023-02-28 12:34

You can use the NumPy library to create random groups of numbers and sort them. Here is a sample code:

``````
import numpy as np

# 创建一个值为100以内的10行10列的随机数组
arr = np.random.randint(0, 100, size=(10, 10))
print("原始数组：\n", arr)

# 按列升序排序
arr_col_asc = np.sort(arr, axis=0)
print("按列升序排序后的数组：\n", arr_col_asc)

# 按列降序排序
arr_col_desc = np.sort(arr, axis=0)[::-1]
print("按列降序排序后的数组：\n", arr_col_desc)

# 使用argsort按行降序排序
arr_row_desc = arr[np.argsort(-arr.sum(axis=1))]
print("使用argsort按行降序排序后的数组：\n", arr_row_desc)

``````

In the above code, np.random.randint(0, 100, size=(10, 10)) is used to create a random set of 10 rows and 10 columns with a value up to 100. The np.sort() function is then used to sort by column ascending and by column descending, where axis=0 means sort by column. For descending column sorting, we use [::-1] to reverse the sorting order. Finally, we use the np.argsort() function to sort the rows in descending order, where -arr.sum(axis=1) means to sum each row and take its negative number(denoted by a negative sign) to achieve descending sort.

dege999 注册会员

Publish Time
2023-02-28 12:34
Update Time
2023-02-28 12:34