Pytorch 张量到 numpy 数组 [英] Pytorch tensor to numpy array

查看:64
本文介绍了Pytorch 张量到 numpy 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 pytorch 大小的张量 torch.Size([4, 3, 966, 1296])

I have a pytorch Tensor of size torch.Size([4, 3, 966, 1296])

我想使用以下代码将其转换为 numpy 数组:

I want to convert it to numpy array using the following code:

imgs = imgs.numpy()[:, ::-1, :, :]

谁能解释一下这段代码在做什么?

Can anyone please explain what this code is doing ?

推荐答案

要转换的张量有 4 个维度.

There are 4 dimensions of the tensor you want to convert.

[:, ::-1, :, :] 

: 表示第一维应该照原样复制和转换,第三和第四维也是如此.

: means that the first dimension should be copied as it is and converted, same goes for the third and fourth dimension.

::-1 表示对于第二个轴,它反转轴

::-1 means that for the second axes it reverses the the axes

这篇关于Pytorch 张量到 numpy 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆