News for hackers. Stuff that matters.
Re:TensorFlow.js: Machine Learning for the Web and Beyond by whalesalad on Tuesday February 05, 2019 @12:26AM (#19083186)
> Two things that JS has over Python is lexical scoping and map/reduce/filter and lambda support.

???

Python does all of that. There are native map/reduce/filter methods in the standard library.

    >>> x = [1, 2, None, 3]
    >>> list(filter(None, x))
    [1, 2, 3]
and then map

    >>> list(map(float, [1, 2, 3]))
    [1.0, 2.0, 3.0]
Lambda's are everywhere in Python:

    >>> double = lambda x: x * 2
    >>> list(map(double, range(3)))
    [0, 2, 4]
https://docs.python.org/3/library/functions.html
Re:TensorFlow.js: Machine Learning for the Web and Beyond by rajangdavis on Tuesday February 05, 2019 @01:08AM (#19083320)
I know that they exist, but if you look at your examples, you have to manually cast maps into a list which is a bit strange coming from Ruby/JS/Scala.

Once you have something sufficiently complex (such as using map, filter, and reduce all at the same time), there becomes so much line noise that it starts working against you.

With JS/Ruby/Scala, you chain functional methods as opposed to Python where you can keep wrapping functions.

Something like

  let arr =  [0,1,2,'test'];

  arr
    .filter(x => typeof(x) == 'number')
    .map(x => x*2)
    .reduce((x, y) => x * y)
becomes a little more cryptic with Python:

  from functools import reduce

  arr = [0,1,2,'test']

  # with lambdas
  reduce(lambda x,y: x + y, map(lambda x: x * 2, filter(lambda x: type(x) == int, arr)))

  # list comprehension equivalent
  sum([x * 2 for x in arr if type(x) == int])
While Python is very beginner friendly, it has a really strange (in my opinion) approach to functional concepts. However, it is has other features that make it really nice to work with (like decorators, data classes, sets, robust ML libraries, really nice built ins).
Re:TensorFlow.js: Machine Learning for the Web and Beyond by naveen99 on Tuesday February 05, 2019 @08:16AM (#19084970)
Chaining function calls makes things harder to debug, so I don’t do it.
Re:TensorFlow.js: Machine Learning for the Web and Beyond by rajangdavis on Wednesday February 06, 2019 @01:08AM (#19093092)
I don't think it's any harder than broadcasting... I try to avoid chaining unless I know the structure of the data I am working with.