I'm wondering if there's a way to do what I can do below with Python, in Ruby:
sum = reduce(lambda x, y: x + y, map(lambda x, y: x * y, weights, data))
I have two arrays of equal sizes with the weights and data but I can't seem to find a function similar to map in Ruby, reduce I have working....
Hi!
I would like to find a way to take JPEG (or GIF/PNG) images and reduce the amount of colors to e.g. 20. Could someone recommend some library or other reference? Also source codes in other languages are welcome.
...
I often need to run reduce (also called foldl / foldr, depending on your contexts) in java to aggregate elements of an Itterable.
Reduce takes a collection/iterable/etc, a function of two parameters, and an optional start value (depending on the implementation details). The function is successively applied to an element of the collec...
In Python map() works on any data that follows the sequence protocol. It does The Right Thing^TM whether I feed it a string or a list or even a tuple.
Can't I have my cake in OCaml too? Do I really have no other choice but to look at the collection type I'm using and find a corresponding List.map or an Array.map or a Buffer.map or a S...
I understand how Map is easily parallelizable - each computer/CPU can just operate on a small portion of the array.
Is Reduce/foldl parallelizable? It seems like each computation depends on the previous one. Is it just parallelizable for certain types of functions?
...
How do you or together all values of a list in Python? I'm thinking something like:
or([True, True, False])
or if it was possible:
reduce(or, [True, True, False])
...
how can i reduce the file size of my flex application. its around 900kb .
...
Hello!
I am trying to write a function that produces a single solution to an underrepresented system of equations (e.g. the matrix that describes the system is wider than it is tall). In order to do this, I have been looking in the LAPACK documentation for a way to row-reduce a matrix to it's reduced-echelon form, similar to the functio...
How can you do this? My code seen here doesn't work
for($i=0;i<count($cond);$i++){
$cond[$i] = $cond[$i][0];
}
...
I found in MSDN's Linq samples a neat method called Fold() that I want to use. Their example:
double[] doubles = { 1.7, 2.3, 1.9, 4.1, 2.9 };
double product =
doubles.Fold((runningProduct, nextFactor) => runningProduct * nextFactor);
Unfortunately, I can't get this to compile, either in their example or in my own code, and I c...
Is there a reduce() list method in Specman that I can use for general reduction functions? I'm thinking of something like:
var x: list of bit = some_function_that_returns_list_of_bit;
var bitmap: uint = x.reduce(foo());
where reduce() works like in Python:
foo(last: uint, val: bit) is: uint {
return (last << 1 ) | bit;
};
...
I learned quite a bit of scheme from SICP but am more interested in common lisp now. I know common lisp's fold is reduce, with special arguments for left or right folding, but what is the equivalent of unfold? Googling has not helped much. In fact I get the impression there is no unfold???
...
The following is my python code:
>>> item = 1
>>> a = []
>>> a.append((1,2,3))
>>> a.append((7,2,4))
>>> sums=reduce(lambda x:abs(item-x[1]),a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: <lambda>() takes exactly 1 argument (2 given)
>>>
How can I fix it?
Thanks!
...
I hope I'm asking this in the right way. I'm learning my way around Elastic MapReduce and I've seen numerous references to the "Aggregate" reducer that can be used with "Streaming" job flows.
In Amazon's "Introduction to Amazon Elastic MapReduce" PDF it states "Amazon Elastic MapReduce has a default reducer called aggregrate"
What I wo...
I'll get to this quick: I have an application for the iPhone OS 3.1.2 that will reduce fractions. I have 4 outlets:
oTop and oBottom: two UITextFields, stands for originalTop and originalBottom.
rTop and rBottom: two UILabels, stands for reducedTop and reducedBottom.
Here is the code I use:
-(IBAction)reduce {
int numerator = [[oTop...
I'm using Firefox 3.5.7 and within Firebug I'm trying to test the array.reduceRight function, it works for simple arrays but when I try something like that I get a NaN. Why?
>>> var details = [{score : 1}, {score: 2}, {score: 3}];
>>> details
[Object score=1, Object score=2, Object score=3]
>>> details.reduceRight(function(x, y) {return...
I have the following project structure
project-parent: All the parent configuration is here
project-ear: Assemblying the ear file from the ejb, war and core projects
project-ejb: EJB module depends on core
project-war: Web module depends on EJB and core
project-core: no dependencies
I was able to use able to use Eclipse or Netbeans a...
Does anyone have expereince with erldmr, a map reduce library for Erlang?
http://code.google.com/p/erldmr/wiki/Paper
...
We have a large table in SQL Server with almost 40.000.000 records. it took considerable time to running queries on it. so we decided to leave all old and out of date records there and move usable records in a new table an use the new one. while it supposed to be faster than old table which have almost double count of records, the proble...
Let's take a function of type (Monad m) => a -> m a. For example:
ghci> let f x = Just (x+1)
I'd like to be able to apply it any number of times. The first thing I tried was
ghci> let times n f = foldr (>=>) return $ replicate n f
The problem is that it won't work for large n:
ghci> 3 `times` f $ 1
Just 4
ghci> 1000000 `times` f $...