analysis专栏 01.科学计算模型nmupy 06.算数函数

 

# 06.算数函数

[toc]{type: "ol", level: [3,4,5]}

### 创建数组
```python
import numpy as numpy
a = numpy.arange(1, 13).reshape(3,4)
b = numpy.arange(2, 14).reshape(3, 4)
```


### 加 add()
```python
a + b
```
::: details result
array([[ 3,  5,  7,  9],
       [11, 13, 15, 17],
       [19, 21, 23, 25]])
:::


### 减 substract()
```python
a - b
```
::: details result
array([[-1, -1, -1, -1],
       [-1, -1, -1, -1],
       [-1, -1, -1, -1]])
:::


### 乘 multiply()
#### 数组相乘
```python
a * b
```
::: details result
array([[  2,   6,  12,  20],
       [ 30,  42,  56,  72],
       [ 90, 110, 132, 156]])
:::
#### 数组与参数相乘
```python
numpy.multiply(a, 12, out=b)
```
::: details result
array([[ 12,  24,  36,  48],
       [ 60,  72,  84,  96],
       [108, 120, 132, 144]])
:::


### 除 divide()
```python
a / b
```
::: details result
array([[0.5       , 0.66666667, 0.75      , 0.8       ],
       [0.83333333, 0.85714286, 0.875     , 0.88888889],
       [0.9       , 0.90909091, 0.91666667, 0.92307692]])
:::


### 少对多
```python
c = numpy.arange(4)
a + c
```
::: details result
array([[ 1,  3,  5,  7],
       [ 5,  7,  9, 11],
       [ 9, 11, 13, 15]])
:::


### 取整
#### 四舍五入
```python
numpy.around(12.5)
numpy.around(12.51)
```
::: details result
12.0
13.0
:::

#### 向上取整
```python
numpy.ceil(12.24)
```
::: details result
13.0
:::

#### 向下取整
```python
numpy.floor(12.68)
```
::: details result
12.0
:::

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值