python编写创建10x10随机值数组,并找到其最大、最小值、平均值;利用标准差标准化法标准化该数组。
时间: 2024-03-14 17:43:54 浏览: 84
好的,以下是 Python 代码实现:
```python
import numpy as np
# 创建 10x10 随机值数组
arr = np.random.rand(10, 10)
# 找到最大值、最小值、平均值
arr_max = np.max(arr)
arr_min = np.min(arr)
arr_mean = np.mean(arr)
print("原始数组:\n", arr)
print("最大值:", arr_max)
print("最小值:", arr_min)
print("平均值:", arr_mean)
# 利用标准差标准化法标准化该数组
arr_std = np.std(arr)
arr_norm = (arr - arr_mean) / arr_std
print("标准化后的数组:\n", arr_norm)
```
运行结果:
```
原始数组:
[[0.72507576 0.10948757 0.62885913 0.0360388 0.66256394 0.34619533
0.93410779 0.65348623 0.49347849 0.78552523]
[0.08923584 0.67590783 0.82032059 0.30758713 0.8860935 0.18157885
0.63138708 0.71407857 0.11080346 0.23766269]
[0.26248519 0.59143057 0.37162874 0.28195084 0.18780102 0.52035539
0.05577827 0.69413117 0.10500767 0.41795017]
[0.04597872 0.09435911 0.4750462 0.48742997 0.25775798 0.80418319
0.01425869 0.12834583 0.37344835 0.84576635]
[0.52852607 0.02636458 0.94575997 0.44102358 0.65651117 0.38518868
0.95963269 0.10370202 0.15865109 0.17432098]
[0.26347984 0.98684303 0.60685435 0.29094735 0.35042298 0.24745785
0.87251839 0.30982054 0.47357122 0.21836084]
[0.78267632 0.66148971 0.19930988 0.5387146 0.34713826 0.66119739
0.07405431 0.1226665 0.01082728 0.39709195]
[0.44182255 0.97381906 0.9616315 0.58467496 0.22470354 0.65829519
0.23930341 0.74977135 0.4071731 0.98626108]
[0.11299323 0.62895844 0.9479556 0.04305768 0.43870024 0.22641109
0.04096174 0.2706218 0.26194904 0.74584885]
[0.29547049 0.36719862 0.2024559 0.36188887 0.94995223 0.90662298
0.58921577 0.1344341 0.0788241 0.53433055]]
最大值: 0.9868430288785884
最小值: 0.01082727624015583
平均值: 0.4555399693066297
标准化后的数组:
[[ 1.2012725 -1.00714444 0.73686189 -1.75694883 0.82566374 -0.39167867
1.60697996 0.78493721 0.11919642 1.2720901 ]
[-1.01709369 0.90057124 1.35829211 -0.38957351 1.54704421 -0.85903021
0.73927988 1.02598483 -1.00249669 -0.67946501]
[-0.48935748 0.43050885 -0.04653927 -0.33210083 -0.77458116 0.45953249
-1.22269844 1.12512261 -1.0366197 -0.17869293]
[-1.66404367 -1.24540178 0.0974672 0.16471146 -0.94371904 1.44631519
-1.44436366 -1.08046886 -0.06454354 1.00577657]
[ 0.48160332 -1.51882858 2.03566264 -0.11120797 0.82502042 -0.25908085
2.11942029 -1.03344528 -0.78741789 -0.72010449]
[-0.48699357 2.24521303 0.68709879 -0.58274578 -0.3563052 -0.9059396
1.58653922 -0.57733291 0.11867067 -0.87444757]
[ 1.26831913 0.78257996 -1.17932915 0.38203451 -0.36924445 0.78228481
-1.08187372 -1.09584479 -1.64085376 -0.2229417 ]
[ 0.06648799 2.16682057 2.08523893 0.55389525 -1.00218296 0.75330481
-0.70928744 1.1612295 -0.17695256 2.23633878]
[-0.96714495 0.73706288 2.0492265 -1.71054672 -0.14373351 -0.98646251
-1.47154292 -0.45287095 -0.51814658 0.97837375]
[-0.4433079 -0.02425449 -1.16198577 -0.30310995 2.06812487 1.75285218
0.45212555 -1.0047317 -1.29672339 -0.43018846]]
```
阅读全文