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())

这个结果是

相关推荐
学习的周周啊14 小时前
ClawdBot(openclaw) + Cloudflare Tunnel + Zero-Trust 零基础保姆教程
网络·人工智能·python·clawdbot
电饭叔14 小时前
DataFrame和 Series 索引
android·python
CELLGENE BIOSCIENCE14 小时前
精准检测,洞见未来|赛唐生物应邀出席2026张江药谷产业发展闭门交流会,共话药物质量安全新篇章
大数据·人工智能
穿过锁扣的风14 小时前
决策树:从入门到实战,解锁 AI 分类预测的核心利器
数据结构·python·决策树
爱学习的阿磊14 小时前
用Python实现自动化的Web测试(Selenium)
jvm·数据库·python
啊阿狸不会拉杆14 小时前
《机器学习导论》第 1 章 - 引言
人工智能·python·算法·机器学习·ai·numpy·matplotlib
coldstarry14 小时前
sheng的学习笔记-AI-adaboost(Adaptive Boosting)
人工智能·笔记·学习
KG_LLM图谱增强大模型14 小时前
Graph-O1:基于蒙特卡洛树搜索与强化学习的文本属性图推理框架
人工智能·知识图谱
北京青翼科技14 小时前
高速采集卡丨AD 采集丨 多通道数据采集卡丨高速数据采集系统丨青翼科技FMC 子卡
图像处理·人工智能·fpga开发·信号处理·智能硬件
轻轻唱14 小时前
2026专业PPT设计服务商推荐:TOP10深度评测与选择指南
大数据·人工智能·算法