import numpy as np
if __name__ == '__main__':
a = np.ones((2, 3))
b = np.ones((2, 3))
c = a + b
d = c + c
print('数组c的形状为{},\n数组为\n{}'.format(c.shape, c))
print('数组d的形状为{},\n数组为\n{}'.format(d.shape, d))
# np数组与np数组的运算——加减乘除幂
e = c + d # 同np.add(c, d)
print('np数组c和d相加为\n{}\n'.format(e), '逐元素相加')
f = c - d # 同np.subtract(c, d)
print('np数组c和d相减为\n{}\n'.format(f), '逐元素相减')
g = c * d # 同np.multiply(c ,d)
print('np数组c和d相乘为\n{}\n'.format(g), '逐元素相乘')
h = c / d # 同np.divide(c, d)
print('np数组c和d相除为\n{}\n'.format(h), '逐元素相除')
i = c ** d # 同np.power(c,d)
print('np数组c和d幂运算为\n{}\n'.format(i), '逐元素幂运算')
# np数组与数字的运算——加减乘除
j = c + 4 # np.add(c, 4)
print('np数组与数字4相加为\n{}\n'.format(j), '逐元素与4相加')
k = c - 4 # np.subtract(c,4)
print('np数组与数字4相减为\n{}\n'.format(k), '逐元素与4相减')
l = c * 4 # np.multiply(c,4)
print('np数组与数字4相乘为\n{}\n'.format(l), '逐元素与4相乘')
m = c / 4 # np.divide(c,4)
print('np数组与数字4相除\n{}\n'.format(m), '逐元素与4相除')
n = c ** 4 # np.power(c,4)
print('np数组与数字4幂运算\n{}\n'.format(n), '逐元素与4幂运算')
07-15
1386
05-31
05-31
05-31
05-31
05-31
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交