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

本站现有博文309篇,共被浏览735821

本站已经建立2373天!

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