numpy-like package for node

前端 未结 9 2190
误落风尘
误落风尘 2021-01-31 01:30

During my years on Python development, I\'ve always been amazed at how much much much faster things become if you manage to rewrite that code that loops though your ndarray and

9条回答
  •  情深已故
    2021-01-31 02:23

    In the same spirit of @Julius's answer about deeplearn.js, tensorflow.js is the continuation of the same project. To play around with the tensorflow module in the REPL, I installed it globally (FYI - it is usually advised not to do this) using this:

    $ npm install --global @tensorflow/tfjs
    

    Then, I ran $ node to start the node REPL.

    This may differ for you (especially if you decided to install tensorflow locally), but I entered this to reference the tensorflow module:

    var tf = require('/usr/local/lib/node_modules/@tensorflow/tfjs')
    

    To create a rank 1 tensor (equivalent to a 1-D array in numpy), try:

    var x = tf.tensor( [-3,4] )
    

    And square it with:

    x.square().print()
    

    You should get [9,16] for your output. See https://js.tensorflow.org for more details.

    I would say that tensorflow.js is not only a JS replacement for numpy, but also for sklearn, keras, and of course, tensorflow.

提交回复
热议问题