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

本站现有博文311篇,共被浏览744228

本站已经建立2387天!

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