创建一个长度为10的随机小数数组小数范围在25 再将数组最小值替换为-99
import random
# 创建长度为10的随机小数数组
arr = [random.uniform(2, 5) for i in range(10)]
print("原始数组:", arr)
# 找出最小值的索引
min_index = arr.index(min(arr))
# 将最小值替换为-99
arr[min_index] = -99
print("替换后的数组:", arr)
输出结果:
原始数组: [3.891970057326969, 4.672618449930623, 2.634719102118762, 2.2042367263230384, 2.696325428162642, 2.1462506669295607, 3.3708324325879885, 2.302981073815655, 3.336984146760527, 4.210414455690094]
替换后的数组: [3.891970057326969, 4.672618449930623, -99, 2.2042367263230384, 2.696325428162642, 2.1462506669295607, 3.3708324325879885, 2.302981073815655, 3.336984146760527, 4.210414455690094]
``
原文地址: https://www.cveoy.top/t/topic/eC2W 著作权归作者所有。请勿转载和采集!