0
Follow
0
View

jupyter program application

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

This answer quotes ChatGPT

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.

About the Author

Question Info

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

Related Question

COM+System Application 无法启动

我的jupyter笔记本julia内核突然开始出现错误

scroll behaviour not working in Nuxt3 Application

Jupyter内核在导入Numpy或Pandas等任何东西时不断重新启动

Vscode“jupyter运行选择/行在交互式窗口”快捷方式不工作

jupyter notebook图片显示异常

无法生成"C:\Program Files\PuTTY\plink.exe":权限被拒绝[重复]

如何实时更新柱状图在Jupyter笔记本?

使用Jupyter笔记本作为函数调用

如何从脚本安装一个新的Jupyter内核