{"id":15419866,"url":"https://github.com/matajoh/libnpy","last_synced_at":"2026-01-16T13:57:20.964Z","repository":{"id":46566413,"uuid":"175852420","full_name":"matajoh/libnpy","owner":"matajoh","description":"Multi-platform C++ library for reading and writing NPY and NPZ files, with an additional .NET interface","archived":false,"fork":false,"pushed_at":"2026-01-10T22:23:39.000Z","size":249,"stargazers_count":24,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-11T04:52:59.698Z","etag":null,"topics":["cpp","cpp-library","npy","npy-files","npz","npz-files"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matajoh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-03-15T16:08:27.000Z","updated_at":"2025-12-22T11:30:49.000Z","dependencies_parsed_at":"2025-04-20T14:01:22.465Z","dependency_job_id":null,"html_url":"https://github.com/matajoh/libnpy","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/matajoh/libnpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matajoh%2Flibnpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matajoh%2Flibnpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matajoh%2Flibnpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matajoh%2Flibnpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matajoh","download_url":"https://codeload.github.com/matajoh/libnpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matajoh%2Flibnpy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp-library","npy","npy-files","npz","npz-files"],"created_at":"2024-10-01T17:26:55.709Z","updated_at":"2026-01-16T13:57:15.955Z","avatar_url":"https://github.com/matajoh.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libnpy\n\n`libnpy` is a multi-platform C++ library for reading and writing NPY and\nNPZ files, with an additional .NET interface. It was built with the \nintention of making it easier for multi-language projects to use NPZ and\nNPY files for data storage, given their simplicity and support across\nmost Python deep learning frameworks.\n\nThe implementations in this library are based upon the following file\nformat documents:\n- **NPY**: The NPY file format is documented by the NumPy developers\n           in [this note](https://docs.scipy.org/doc/numpy/reference/generated/numpy.lib.format.html)\n- **NPZ**: While not explicitly documented, the NPZ format is a\n           a PKZIP archive of NPY files, and thus is documented\n           here: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT.\n\n## Getting Started\n\nStart by installing [CMake](https://cmake.org/) in the way appropriate for your\nenvironment.\n\n### Linux\n\nCreate a build directory and initialize the cmake project:\n\n    mkdir build\n    cd build\n    cmake .. --preset release\n\nYou can then build and run the tests using:\n\n    make\n    ctest\n\n### Windows\n\nCreate a build directory and initialize the cmake project:\n\n    mkdir build\n    cd build\n    cmake .. --preset release\n\nYou can then build and run the tests using:\n\n    cmake --build . --config Release\n    ctest -C Release\n\n## Sample code\n\nOnce the library has been built and installed, you can begin to use it\nin your code. We have provided some\n[sample programs](https://github.com/matajoh/libnpy/tree/main/samples)\n(and naturally the [tests](https://github.com/matajoh/libnpy/tree/main/test)\nas well) which show how to use the library, but the basic concepts are as follows.\nFor the purpose of this sample code we will use the built-in [tensor](src/tensor.h)\nclass, but you should use your own tensor class as appropriate.\n\n```C++\n#include \"tensor.h\"\n#include \"npy.h\"\n#include \"npz.h\"\n\n...\n    // create a tensor object\n    std::vector\u003csize_t\u003e shape({32, 32, 3});\n    npy::tensor\u003cstd::uint8_t\u003e color(shape);\n\n    // fill it with some data\n    for (int row = 0; row \u003c color.shape(0); ++row)\n    {\n        for (int col = 0; col \u003c color.shape(1); ++col)\n        {\n            color(row, col, 0) = static_cast\u003cstd::uint8_t\u003e(row \u003c\u003c 3);\n            color(row, col, 1) = static_cast\u003cstd::uint8_t\u003e(col \u003c\u003c 3);\n            color(row, col, 2) = 128;\n        }\n    }\n\n    // save it to disk as an NPY file\n    npy::save(\"color.npy\", color);\n\n    // we can manually set the endianness to use\n    npy::save(\"color.npy\", color, npy::endian_t::BIG);\n\n    // the built-in tensor class also has a save method\n    color.save(\"color.npy\");\n\n    // we can peek at the header of the file\n    npy::header_info header = npy::peek(\"color.npy\");\n\n    // we can load it back the same way\n    color = npy::load\u003cstd::uint8_t, npy::tensor\u003e(\"color.npy\");\n\n    // let's create a second tensor as well\n    shape = {32, 32};\n    npy::tensor\u003cfloat\u003e gray(shape);\n\n    for (int row = 0; row \u003c gray.shape(0); ++row)\n    {\n        for (int col = 0; col \u003c gray.shape(1); ++col)\n        {\n            gray(row, col) = 0.21f * color(row, col, 0) +\n                             0.72f * color(row, col, 1) +\n                             0.07f * color(row, col, 2);\n        }\n    }\n\n    // we can write them to an NPZ file\n    {\n        npy::onpzstream output(\"test.npz\");\n        output.write(\"color.npy\", color);\n        output.write(\"gray.npy\", gray);\n    }\n\n    // and we can read them back out again\n    {\n        npy::inpzstream input(\"test.npz\");\n\n        // we can test to see if the archive contains a file\n        if (input.contains(\"color.npy\"))\n        {\n            // and peek at its header\n            header = input.peek(\"color.npy\");\n        }\n\n        color = input.read\u003cstd::uint8_t\u003e(\"color.npy\");\n        gray = input.read\u003cfloat\u003e(\"gray.npy\");\n    }\n```\n\nThe generated documentation contains more details on all of the functionality.\nWe hope you find that the library fulfills your needs and is easy to use, but\nif you have any difficulties please create\n[issues](https://github.com/matajoh/libnpy/issues) so the maintainers can make\nthe library even better. Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatajoh%2Flibnpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatajoh%2Flibnpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatajoh%2Flibnpy/lists"}