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

本站现有博文321篇,共被浏览775283

本站已经建立2466天!

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