Pytorch中ndarray tensor list互转
2024-09-05 00:59:59
1.ndarray->tensor :
b=torch.from_numpy(a)
2.tensor->ndarray:
b=a.numpy()
'''
但这么写会报错……
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.
'''
# 修改为
b=a.detach().numpy()
'''
gpu上的tensor不能直接转为numpy
'''
b=a.cpu().numpy()
3.ndarray->list
b=a.tolist()
4.list->ndarray
b=numpy.array(a)
最新文章
- 基于Bootstrap里面的Button dropdown打造自定义select
- ProgressBar
- 用eclipse做项目中常遇到的问题-如何创建并读取properties文件
- Swift内存管理、weak和unowned以及两者区别
- 自定义Dialog之信息提示
- 各种 starter poms (启动器)
- 为SpringMvc项目安装BootStrap和AngularJs前端框架
- javascript自执行匿名函数
- Objective-C中字典的使用方法总结
- [react native] Error loading page
- HDU 1162 Eddy's picture
- tcpdump 抓包让wireshark来分析
- [转]new一个Object对象占用多少内存?
- HTML一些小细节
- Delphi临界区的使用
- python:发送消息给微信企业号
- 「洛谷4197」「BZOJ3545」peak【线段树合并】
- Html5与Css3知识点拾遗(一)
- 【代码笔记】iOS-获得现在的时间(2015-09-11)
- 格式化输出函数:printf 那些事 (C语言)
热门文章
- Computer Networking: A Top Down Approach
- ASP.NET Core中返回 json 数据首字母大小写问题
- FreePascal - CodeTyphon 如何调整代码编辑器背景色?
- mysql-luster没有data目录
- php集成开发环境搭建三种方式
- unittest管理用例生成测试报告
- OSPF 高级配置
- 记录SQLAlchemy的基本使用
- maven nexus 私服搭建 Windows版
- php72w-common conflicts with php-common-5.4.16-46.el7.x86_64