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

这个结果是

相关推荐
普密斯科技2 分钟前
如何一键解决手机镜头磨切片微米级尺寸测量难题?
人工智能·计算机视觉·智能手机·测量
qq_454245033 分钟前
认知自举:LLM自我指令泛化的三层逻辑
人工智能·架构·prompt
Luminbox紫创测控5 分钟前
可调UV宽光谱高功率的LED太阳能模拟器
人工智能·测试工具·汽车·安全性测试·uv·测试标准
董员外12 分钟前
RAG 系统进化论(一):纵览 RAG 的发展历程
前端·人工智能·后端
殷紫川14 分钟前
Agent Skills:把团队里"只会做一遍"的经验,变成 Agent 能反复调用的能力包
人工智能·agent
AI搅拌机18 分钟前
LoRA训练实战10:Wan2.2人物变火特效LoRA极简训练法,上手指南!
人工智能
京东云开发者25 分钟前
别再守着 Claude Code 了——学会指挥它自主干活
人工智能
大模型码小白28 分钟前
在 Windows 下 Codex 安装、配置与使用详细指南
java·人工智能·windows
小大宇31 分钟前
python milvus 案例
开发语言·python·milvus
MobotStone43 分钟前
AI写代码,真的能做出“能用”的产品吗?
人工智能