pytorch奇怪错误

复制代码
ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array  with array.copy().) 

今天在这里遇到了一个奇怪的bug

复制代码
import numpy as np

# 创建一个简单的数组
array = np.array([1, 2, 3, 4, 5])

# 使用反向切片创建负步幅数组
reversed_array = array[::-1]

print("原始数组:", array)
print("反向切片后的数组:", reversed_array)
print("反向数组的步幅:", reversed_array.strides)

结果如下

复制代码
import torch 
aa = torch.FloatTensor(array)
bb = torch.FloatTensor(reversed_array)

正确用法

复制代码
import torch 
aa = torch.FloatTensor(array)
bb = torch.FloatTensor(reversed_array.copy())

这个结果是

相关推荐
lpfasd123几秒前
python webview打包版卡死、开发版正常
开发语言·python
用户83562907805110 分钟前
如何使用 Python 为 PowerPoint 幻灯片添加切换效果
后端·python
菜冻鱼18 分钟前
Python-pytorch-模型保存与加载
开发语言·人工智能·pytorch·python·深度学习·机器学习
程序员cxuan31 分钟前
Claude Code :如何最大化你的 Session 价值
人工智能·后端·程序员
亿牛云爬虫专家32 分钟前
爬虫调度系统设计:用 Celery 实现按媒体权重动态调整的抓取频率控制
爬虫·python·隧道代理·舆情采集·媒体权重·频率控制·ip自动轮换
MatrixOrigin38 分钟前
MatrixOne Git4Data 技术详解(十一)·大模型篇:SFT 数据 curation——可审计、可复现的数据清洗
人工智能·矩阵起源·数据底座·git4data
小酒星小杜1 小时前
AI漫画真正的门槛,不是出图,而是让角色持续出演
人工智能·产品·全栈
数智大号1 小时前
从机器人前置仓到机器人组装机器人,星海图 WRC 打开具身智能产业化下半场
人工智能·机器人
Code额1 小时前
Python 连接 DeepSeek API,OpenAI
开发语言·python·ai·ai编程