3

I need to translate a Python program into Javascript and I see numpy.apply_along_axis many times but do not know how to do that in Javascript. Please help!

  • 1
    The Javascript arrays are like Python lists. There's no inherent notion of axis or multidimensions. Are you using any packages to enhance the array functionality? Something like `underscore.js`? – hpaulj Jun 25 '15 at 18:31
  • I just started using Javascript and I don't know about any packages. Does the one you mention have something similar? – sosprogramming Jun 25 '15 at 18:39
  • `underscore` (and clones) makes it easier to iterate through the various Javascript 'collections'. But it is not a `numpy` like package. Some other things that might make transition easier: JSON, Coffeescript, nodejs. – hpaulj Jun 25 '15 at 18:53

1 Answers1

0

There various ideas of how to create 'multidimensional arrays' in Javascript in this SO question from a few years back

JavaScript multidimensional array

Basically all use nested arrays, the equivalent of Python nested lists.

You have to have some sort of multidimensional array to have a concept of 'axis'. Inevitably some operations will be easier on the first level array than on the deepest level. And there will be speed penalties.

And for a syntax that looks more like Python, consider Coffeescript

Coffee script multidimensional array creation

Packages like underscore.js and lodash have array/collection iterators and functions that can make operation on arrays easier. There are, for example, zip and flatten functions.

https://lodash.com/docs

Community
  • 1
  • 1
hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • The main point of `numpy` isn't to make it easy to create lists of lists. It is to provide high-performance, memory-efficient and blas-compatible arrays in python. Lists of lists are thousands of times slower than `numpy` arrays in python. I guess something similar could be created using asm.js, and I'm a bit surprised it doesn't already exist. – amaurea Jan 02 '16 at 18:16