创建100个服从正态分布的随机数,数组形态为2维数组。 创建两个数组,进行四则运算。
时间: 2024-05-04 09:15:16 浏览: 83
1. 创建100个服从正态分布的随机数,数组形态为2维数组。
```
import numpy as np
# 创建100个服从正态分布的随机数,平均值为0,标准差为1
random_array = np.random.normal(loc=0, scale=1, size=(10, 10))
print(random_array)
```
输出结果:
```
[[ 1.58403399 -0.10708586 -0.33032397 -0.03150921 -0.43497317 -1.12121572
-0.0576707 -0.78138983 0.33553447 -0.47683704]
[-0.5837484 1.09483089 0.32110942 -0.21779268 0.02049916 1.42242397
-0.56208997 0.86234677 -0.03356192 -0.12947078]
[-0.23615879 -0.68823262 1.80317244 1.26787951 -0.10116679 -0.47850269
1.21534572 -0.08091856 -0.41615581 -0.99106531]
[-0.71784405 -0.08084137 0.37621459 0.15882724 1.08070536 -0.22862208
-0.44143177 -1.42693731 -0.27707092 -0.29132184]
[-0.60747839 1.66943888 0.45077909 0.98323813 0.96330314 -0.61798954
-0.16778588 -1.04463985 -0.18662717 -0.08653691]
[ 1.36014834 -0.03517684 -0.55814769 -0.47150167 0.39782467 0.49947238
0.66145669 0.33480156 1.24737369 -0.40054345]
[-0.41557057 -0.10793134 1.94208362 -0.82784979 1.00463226 -0.10606322
0.3020052 0.45040117 -1.01716158 -0.09485435]
[-0.55478657 -0.51015973 -1.13279017 -0.03836616 -1.21272901 -0.56031507
1.12403227 0.33412344 -0.74009205 -0.89363479]
[ 0.41918952 -0.45942749 -0.94743309 0.1314538 -0.33664562 -0.57856932
0.80216708 1.21615333 0.45063112 1.14037838]
[-0.97330677 0.08434117 0.20790368 -0.70403177 -0.09798388 -0.30092771
1.83698567 0.02022313 0.4296769 -0.56677122]]
```
2. 创建两个数组,进行四则运算。
```
import numpy as np
# 创建两个数组
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
# 四则运算
c = a + b
d = a - b
e = a * b
f = a / b
print(c)
print(d)
print(e)
print(f)
```
输出结果:
```
[[ 6 8]
[10 12]]
[[-4 -4]
[-4 -4]]
[[ 5 12]
[21 32]]
[[0.2 0.33333333]
[0.42857143 0.5 ]]
```
阅读全文