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

这个结果是

相关推荐
科雷软件测试1 小时前
Python中itertools.product:快速生成笛卡尔积
开发语言·python
IT_陈寒3 小时前
React Hooks闭包陷阱:你以为的state可能早就过期了
前端·人工智能·后端
派大星~课堂4 小时前
【力扣-142. 环形链表2 ✨】Python笔记
python·leetcode·链表
Thomas.Sir4 小时前
第一章:Agent智能体开发实战之【初步认识 LlamaIndex:从入门到实操】
人工智能·python·ai·检索增强·llama·llamaindex
笨笨饿4 小时前
29_Z变换在工程中的实际意义
c语言·开发语言·人工智能·单片机·mcu·算法·机器人
boy快快长大4 小时前
【大模型应用开发】记忆
人工智能
LaughingZhu4 小时前
Product Hunt 每日热榜 | 2026-04-05
前端·数据库·人工智能·经验分享·神经网络
OPHKVPS4 小时前
GoBruteforcer(GoBrut)僵尸网络新攻势:AI 生成弱配置成“帮凶”,瞄准加密货币及区块链数据库
网络·人工智能·区块链
ZTL-NPU5 小时前
Jetbrains开发ros
ide·python·pycharm·编辑器·ros·clion
打乒乓球只会抽5 小时前
AI Agent:大模型+工具的智能革命
人工智能