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

这个结果是

相关推荐
君臣Andy3 分钟前
AI 搜索引擎 MindSearch
人工智能·ai 搜索引擎
小洛~·~6 分钟前
多模态RAG与LlamaIndex——1.deepresearch调研
人工智能·python·深度学习·神经网络·chatgpt
SunsPlanter6 分钟前
快速入门机器学习的专有名词
人工智能·机器学习
AndrewHZ12 分钟前
【图像处理基石】遥感图像分析入门
图像处理·人工智能·深度学习·计算机视觉·遥感图像·技术分析·多光谱
石臻臻的杂货铺16 分钟前
推荐几个常用免费的文本转语音工具
人工智能·语音识别
Thanks_ks19 分钟前
人工智能技术演进:从多模态融合到智能体落地的实践探索
人工智能·多模态融合·技术趋势·智能体 ai·小模型优化·rag 技术·代码实践
uesowys29 分钟前
阿里云人工智能大模型通义千问Qwen3开发部署
人工智能·阿里云·qwen3
摆烂仙君42 分钟前
浅论3DGS溅射模型在VR眼镜上的应用
人工智能·深度学习·vr
程序小K43 分钟前
OpenCV的CUDA模块进行图像处理
图像处理·人工智能·opencv
jndingxin44 分钟前
OpenCVCUDA 模块中在 GPU 上对图像或矩阵进行 边界填充(padding)函数copyMakeBorder()
人工智能·opencv