Giter Site home page Giter Site logo

pombredanne / rcppcnpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eddelbuettel/rcppcnpy

0.0 2.0 0.0 1.14 MB

Rcpp bindings for NumPy files

License: GNU General Public License v2.0

R 17.15% Shell 0.52% TeX 4.13% C++ 76.92% Python 1.27%

rcppcnpy's Introduction

RcppCNPy: Rcpp bindings for NumPy files

Build Status License CRAN Downloads status DOI

About

This package uses the cnpy library written by Carl Rogers to provide read and write facilities for files created with (or for) the NumPy extension for Python. Vectors and matrices of numeric types can be read or written to and from files as well as compressed files. Support for integer files is available if the package has been built with -std=c++11 which is the default starting with release 0.2.3 following the release of R 3.1.0, and available on all platforms following the release of R 3.3.0 with the updated 'Rtools'.

Example

The following Python code

>>> import numpy as np
>>> fm = np.arange(12).reshape(3,4) * 1.1
>>> fm
array([[  0. ,   1.1,   2.2,   3.3],
       [  4.4,   5.5,   6.6,   7.7],
       [  8.8,   9.9,  11. ,  12.1]])
>>> np.save("fmat.npy", fm)
>>> 
>>> im = np.arange(12).reshape(3,4)
>>> im
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
>>> np.save("imat.npy", im)
>>> 

saves two matrices in floating-point and integer representation.

With this R code we can read and assign the files:

R> library(RcppCNPy)
R> fmat <- npyLoad("fmat.npy")
R> fmat
     [,1] [,2] [,3] [,4]
[1,]  0.0  1.1  2.2  3.3
[2,]  4.4  5.5  6.6  7.7
[3,]  8.8  9.9 11.0 12.1
R> 
R> imat <- npyLoad("imat.npy", "integer")
R> imat
     [,1] [,2] [,3] [,4]
[1,]    0    1    2    3
[2,]    4    5    6    7
[3,]    8    9   10   11
R> 

Going the opposite way by saving in R and reading in Python works equally well. An extension not present in CNPy allows reading and writing of gzip-compressed files.

The package has been tested and used on several architecture, and copes correctly with little-vs-big endian switches.

More details are available in the package vignette.

Installation

The package is on CRAN and can be installed per:

R> install.packages(RCppCNPy)

Status

On CRAN, stable and mostly feature-complete.

Feedback

Contributions are welcome, please use the GitHub issue tracker for bug reports, feature requests or general discussions before sending pull requests.

Author

Dirk Eddelbuettel and Wush Wu

License

GPL (>= 2)

rcppcnpy's People

Contributors

eddelbuettel avatar romainfrancois avatar wush978 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.