按正态分布(高斯分布)对数字数组进行排序的方法可以分为以下几个步骤:
import numpy as np
# 生成一个包含100个随机数字的数组
arr = np.random.randn(100)
# 对数组进行排序并获取排序后的索引值
sorted_indices = np.argsort(arr)
# 根据索引值重新排序原始数组
sorted_arr = arr[sorted_indices]
完整的代码示例:
import numpy as np
arr = np.random.randn(100)
sorted_indices = np.argsort(arr)
sorted_arr = arr[sorted_indices]
print("原始数组:", arr)
print("排序后的数组:", sorted_arr)
这样就可以按正态分布(高斯分布)对数字数组进行排序了。