如何使用np.random.random()生成10*10数组并打印其最大最小元素
时间: 2024-04-29 19:23:03 浏览: 40
可以使用以下代码生成10 * 10数组,并打印其最大和最小元素:
```
import numpy as np
# 生成10 * 10数组
arr = np.random.random((10, 10))
# 打印数组
print(arr)
# 打印最大和最小元素
print("最大元素:", np.max(arr))
print("最小元素:", np.min(arr))
```
输出结果类似于:
```
[[0.71894627 0.62366502 0.19155198 0.57040062 0.45042385 0.85073481
0.56506056 0.03628025 0.70038718 0.38070712]
[0.83684164 0.09443424 0.91077688 0.82084683 0.13874294 0.13409032
0.5416033 0.31270208 0.21835777 0.7517247 ]
[0.24688797 0.87218041 0.15955735 0.5979601 0.80267603 0.56485511
0.76381381 0.18786193 0.52854945 0.92339381]
[0.69696683 0.7693273 0.68147383 0.48075916 0.07481023 0.69543839
0.10989322 0.73667865 0.60406932 0.07842646]
[0.00214273 0.04990628 0.40215375 0.27288061 0.76429306 0.86708334
0.14795511 0.14876594 0.56418828 0.16510239]
[0.24057164 0.06737983 0.8099694 0.28227255 0.60497028 0.19118444
0.32420177 0.56985056 0.19570966 0.12560161]
[0.53097192 0.97398881 0.43059132 0.74544654 0.11405493 0.14233202
0.27819193 0.6147982 0.54072707 0.64683886]
[0.94396185 0.07958865 0.17837608 0.60773809 0.86835639 0.61141811
0.47594223 0.0812574 0.47242787 0.3834021 ]
[0.74487585 0.21252529 0.3222836 0.94717116 0.32723257 0.67423833
0.17558994 0.73575862 0.96984409 0.13171811]
[0.31169335 0.74348939 0.28791556 0.15763772 0.86715806 0.33278797
0.73183876 0.27266281 0.484817 0.05623332]]
最大元素: 0.9739888149374885
最小元素: 0.0021427289570559666
```
阅读全文