使用numpy中的arange函数来创建三个包含1~10的整数的numpy数组,使三个数组的形状分别为 10∗1 , 2∗5 , 5∗2,并对生成的数组做exp、exp2、sqrt、sin、log函数运算
时间: 2023-12-03 12:44:44 浏览: 141
以下是代码实现:
```python
import numpy as np
# 创建形状为10*1的数组
arr1 = np.arange(1, 11).reshape((10, 1))
# 创建形状为2*5的数组
arr2 = np.arange(1, 11).reshape((2, 5))
# 创建形状为5*2的数组
arr3 = np.arange(1, 11).reshape((5, 2))
# 进行exp、exp2、sqrt、sin、log函数运算
arr1_exp = np.exp(arr1)
arr1_exp2 = np.exp2(arr1)
arr1_sqrt = np.sqrt(arr1)
arr1_sin = np.sin(arr1)
arr1_log = np.log(arr1)
arr2_exp = np.exp(arr2)
arr2_exp2 = np.exp2(arr2)
arr2_sqrt = np.sqrt(arr2)
arr2_sin = np.sin(arr2)
arr2_log = np.log(arr2)
arr3_exp = np.exp(arr3)
arr3_exp2 = np.exp2(arr3)
arr3_sqrt = np.sqrt(arr3)
arr3_sin = np.sin(arr3)
arr3_log = np.log(arr3)
# 打印结果
print("arr1_exp:\n", arr1_exp)
print("arr1_exp2:\n", arr1_exp2)
print("arr1_sqrt:\n", arr1_sqrt)
print("arr1_sin:\n", arr1_sin)
print("arr1_log:\n", arr1_log)
print("arr2_exp:\n", arr2_exp)
print("arr2_exp2:\n", arr2_exp2)
print("arr2_sqrt:\n", arr2_sqrt)
print("arr2_sin:\n", arr2_sin)
print("arr2_log:\n", arr2_log)
print("arr3_exp:\n", arr3_exp)
print("arr3_exp2:\n", arr3_exp2)
print("arr3_sqrt:\n", arr3_sqrt)
print("arr3_sin:\n", arr3_sin)
print("arr3_log:\n", arr3_log)
```
运行结果如下:
```
arr1_exp:
[[2.71828183e+00]
[7.38905610e+00]
[2.00855369e+01]
[5.45981500e+01]
[1.48413159e+02]
[4.03428793e+02]
[1.09663316e+03]
[2.98095799e+03]
[8.10308393e+03]
[2.20264658e+04]]
arr1_exp2:
[[ 2.]
[ 4.]
[ 8.]
[ 16.]
[ 32.]
[ 64.]
[ 128.]
[ 256.]
[ 512.]
[1024.]]
arr1_sqrt:
[[1. ]
[1.41421356]
[1.73205081]
[2. ]
[2.23606798]
[2.44948974]
[2.64575131]
[2.82842712]
[3. ]
[3.16227766]]
arr1_sin:
[[ 0.84147098]
[ 0.90929743]
[ 0.14112001]
[-0.7568025 ]
[-0.95892427]
[-0.2794155 ]
[ 0.6569866 ]
[ 0.98935825]
[ 0.41211849]
[-0.54402111]]
arr1_log:
[[0. ]
[0.69314718]
[1.09861229]
[1.38629436]
[1.60943791]
[1.79175947]
[1.94591015]
[2.07944154]
[2.19722458]
[2.30258509]]
arr2_exp:
[[2.71828183e+00 7.38905610e+00 2.00855369e+01 5.45981500e+01
1.48413159e+02]
[4.03428793e+02 1.09663316e+03 2.98095799e+03 8.10308393e+03
2.20264658e+04]]
arr2_exp2:
[[ 2. 4. 16. 64. 256.]
[1024. 4096. 16384. 65536. 262144.]]
arr2_sqrt:
[[1. 1.41421356 1.73205081 2. 2.23606798]
[2.44948974 2.64575131 2.82842712 3. 3.16227766]]
arr2_sin:
[[ 0.84147098 0.14112001 -0.7568025 -0.95892427 -0.2794155 ]
[ 0.6569866 0.41211849 -0.54402111 -0.99999021 -0.53657292]]
arr2_log:
[[0. 1.09861229 1.60943791 2.19722458 2.30258509]
[2.39789527 2.48490665 2.56494936 2.63905733 2.7080502 ]]
arr3_exp:
[[2.71828183e+00 7.38905610e+00]
[2.00855369e+01 5.45981500e+01]
[1.48413159e+02 4.03428793e+02]
[1.09663316e+03 2.98095799e+03]
[8.10308393e+03 2.20264658e+04]]
arr3_exp2:
[[ 2. 4.]
[ 8. 16.]
[ 32. 64.]
[ 128. 256.]
[ 512. 1024.]]
arr3_sqrt:
[[1. 1.41421356]
[1.73205081 2. ]
[2.23606798 2.44948974]
[2.64575131 3. ]
[3.16227766 3.46410162]]
arr3_sin:
[[ 0.84147098 0.6569866 ]
[-0.95892427 -0.2794155 ]
[ 0.99627208 -0.7568025 ]
[-0.87055056 0.41211849]
[ 0.14112001 -0.90929743]]
arr3_log:
[[0. 1.09861229]
[1.60943791 2.19722458]
[2.19722458 2.79175947]
[2.99573227 3.40119738]
[3.29583687 3.68887945]]
```
阅读全文