API pytorch tensorflow
生活随笔
收集整理的這篇文章主要介紹了
API pytorch tensorflow
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
pytorch與tensorflow API速查表
| 方法名稱 | pytroch | tensorflow | numpy |
|---|---|---|---|
| 裁剪 | torch.clamp(x, min, max) | tf.clip_by_value(x, min, max) | np.clip(x, min, max) |
| 取最大值 | torch.max(x, dim)[0] | tf.max(x, axis) | np.max(x, axis) |
| 取最小值 | torch.min(x, dim)[0] | tf.min(x, axis) | np.min(x , axis) |
| 取兩個tensor的最大值 | torch.max(x, y) | tf.maximum(x, y) | np.maximum(x, y) |
| 取兩個tensor的最小值 | torch.min(x, y) | torch.minimum(x, y) | np.minmum(x, y) |
| 取最大值索引 | torch.max(x, dim)[1] | tf.argmax(x, axis) | np.argmax(x, axis) |
| 取最小值索引 | torch.min(x, dim)[1] | tf.argmin(x, axis) | np.argmin(x, axis) |
| 比較(x > y) | torch.gt(x, y) | tf.greater(x, y) | np.greater(x, y) |
| 比較(x < y) | torch.le(x, y) | tf.less(x, y) | np.less(x, y) |
| 比較(x==y) | torch.eq(x, y) | tf.equal(x, y) | np.equal(x, y) |
| 比較(x!=y) | torch.ne(x, y) | tf.not_equal(x, y) | np.not_queal(x , y) |
| 取符合條件值的索引 | torch.nonzero(cond) | tf.where(cond) | np.where(cond) |
| 多個tensor聚合 | torch.cat([x, y], dim) | tf.concat([x,y], axis) | np.concatenate([x,y], axis) |
| 堆疊成一個tensor | torch.stack([x1, x2], dim) | tf.stack([x1, x2], axis) | np.stack([x, y], axis) |
| tensor切成多個tensor | torch.split(x1, split_size_or_sections, dim) | tf.split(x1, num_or_size_splits, axis) | np.split(x1, indices_or_sections, axis) |
| – | torch.unbind(x1, dim) | tf.unstack(x1,axis) | NULL |
| 隨機擾亂 | torch.randperm(n)1 | tf.random_shuffle(x) | np.random.shuffle(x)2 np.random.permutation(x)3 |
| 前k個值 | torch.topk(x, n, sorted, dim) | tf.nn.top_k(x, n, sorted) | NULL |
該方法只能對0~n-1自然數隨機擾亂,所以先對索引隨機擾亂,然后再根據擾亂后的索引取相應的數據得到擾亂后的數據 ??
該方法會修改原值,沒有返回值 ??
該方法不會修改原值,返回擾亂后的值 ??
總結
以上是生活随笔為你收集整理的API pytorch tensorflow的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tensor转换 pytorch t
- 下一篇: python 虚拟环境 tensorfl