EADST

Python Numpy Array to C++ Vector

Python Numpy Array to C++ Vector

# Save the Numpy in a txt.
import numpy as np

s = ''
data = np.load("data.npy")
c, h, w = data.shape
data = data.reshape(c*h*w)
for v in data:
    s += str(v) + '\t'
path = "data.txt"
f = open(path, "w+")
f.write(s)
// load the txt file and save in a float vector
#include < iostream>
#include < fstream>
#include < string>
#include < vector>

using namespace std;


std::string txtPath = "data.txt";
ifstream InFile;
InFile.open (txtPath);
std::vector data_vector;
if (InFile)
{
    string line;
    float number;
    for (int i = 0; i < 1; ++i)
    {
        getline (InFile, line);
        istringstream iss(line);
        while (iss >> number)
        {
            data_vector.push_back (number);
        }

     }
     InFile.close ();
     InFile.clear ();
 }
 else
     throw runtime_error ("document error");
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
RL PDB XML Datetime FastAPI 签证 RAR Bitcoin HaggingFace Pillow 云服务器 Use TSV Hungarian Statistics Nginx CLAP Tracking Ptyhon Image2Text ms-swift v2ray PyCharm PIP Website Magnet Paddle COCO Rebuttal ModelScope VSCode Conda Harness GGML News UNIX Llama Google VPN Qwen2 Proxy HuggingFace Food 腾讯云 Safetensors Attention TensorRT Template PyTorch WebCrawler Ubuntu BF16 mmap Search llama.cpp Algorithm 强化学习 CTC Interview TensorFlow Bert LoRA Heatmap Quantization NLTK Data Linux 图标 Shortcut logger torchinfo diffusers ResNet-50 hf uwsgi Base64 Git Excel TTS Python 图形思考法 自我改进 CSV Markdown JSON Numpy DeepStream Pytorch Animate git VGG-16 GoogLeNet NameSilo Disk Miniforge RGB 继承 Transformers Hotel AI Freesound SQLite Zip 公式 scipy 阿里云 v0.dev 净利润 SAM 财报 论文速读 SQL Plate Sklearn CC API OpenAI WAN Logo 证件照 Web FP32 Streamlit Quantize Firewall Docker Vim SVR ONNX GIT 算法题 Plotly Clash CEIR GPTQ EXCEL Agent InvalidArgumentError BeautifulSoup CAM OCR GPT4 关于博主 C++ 顶会 tqdm Math Crawler Bipartite Mixtral YOLO Review LLM Dataset 递归学习法 uWSGI 论文 搞笑 ChatGPT XGBoost BTC 域名 Knowledge Domain transformers PDF Card Vmess API网关 FP16 Gemma FP8 Hilton Qwen2.5 UI MD5 Translation Windows Permission Michelin printf icon DeepSeek Distillation SPIE Cloudreve Augmentation LeetCode Breakpoint Paper Jev Django 长期记忆 FlashAttention Password Pandas Qwen QWEN Claude FP64 IndexTTS2 LLAMA LaTeX tar CUDA 多进程 多线程 git-lfs Input Baidu OpenCV Jupyter Diagram 报税 NLP Jetson 音频 第一性原理 Color Tensor Tiktoken Random 版权 Land CV 飞书 Video Pickle Anaconda Bin Github
站点统计

本站现有博文339篇,共被浏览1000171次

本站已经建立2710天!

热门文章
文章归档
回到顶部