Reduce refers to the operation, where a array of items is reduced to a single value. Use with language tag like [c++], [google-sheets-formula]. Do NOT use alone.
Questions tagged [reduce]
3548 questions
17
votes
2 answers
Is the accumulator of reduce in Java 8 allowed to modify its arguments?
In Java 8, Stream has a method reduce:
T reduce(T identity, BinaryOperator accumulator);
Is the accumulator operator allowed to modify either of its arguments? I presume not since the JavaDoc says the accumulator should be NonInterfering,…

Graeme Moss
- 7,995
- 4
- 29
- 42
16
votes
7 answers
tidyverse: binding list elements of same dimension
Using reduce(bind_cols), the list elements of same dimension may be combined. However, I would like to know how to combine only same dimension (may be specified dimesion in some way) elements from a list which may have elements of different…

MYaseen208
- 22,666
- 37
- 165
- 309
16
votes
2 answers
give type to accumulator with array reduce typescript
I am generating object with time intervals with some function. It returns ["00:00", "00:30", "01:00"] ... , but for my purpose I need to have obj-map {{ "00:00": "00:00" }, { "00:30": "00:30" }, { "01:00": "01:00" }}.
I have trouble typing the…

Igor Pavlenko
- 631
- 1
- 8
- 15
16
votes
1 answer
Java stream merge or reduce duplicate objects
I need to generate a unique friend list from a list that can have duplicates by merging all duplicate entries into one object
Example - Friends are fetched from different social feeds and put into 1 big list
1. Friend - [name: "Johnny Depp", dob:…

Vku
- 163
- 1
- 1
- 7
16
votes
6 answers
Real world examples of using reduceRight in JavaScript
A while ago, I posted a question on StackOverflow showing that the native implementation of reduceRight in JavaScript is annoying. Hence, I created a Haskell-style foldr function as a remedy:
function foldr(array, callback, initial) {
var length…

Aadit M Shah
- 72,912
- 30
- 168
- 299
15
votes
1 answer
MPI Get Processor with Minimum value
In MPI, I am doing a reduce operation(minimum) on a value. This works fine, but how do I grab the processor number that the minimum came from and solicit that processor for more information(or send the additional data with the reduce operation)?

James Cotter
- 798
- 11
- 22
15
votes
1 answer
Reductions in parallel in logarithmic time
Given n partial sums it's possible to sum all the partial sums in log2 parallel steps. For example assume there are eight threads with eight partial sums: s0, s1, s2, s3, s4, s5, s6, s7. This could be reduced in log2(8) = 3 sequential steps like…

Z boson
- 32,619
- 11
- 123
- 226
14
votes
3 answers
Is it valid to reduce on an empty set of sets?
Shouldn't this work?
> val setOfSets = Set[Set[String]]()
setOfSets: scala.collection.immutable.Set[Set[String]] = Set()
> setOfSets reduce (_ union _)
java.lang.UnsupportedOperationException: empty.reduceLeft
at…

gladed
- 1,705
- 1
- 17
- 25
14
votes
1 answer
null key in from map/reduce result in couchdb
For some reason I'm only getting a null key from map/reduce result in couchdb on mac
Result:
{"rows":[
{"key":null,"value":2224}
]}
Im using couchapp v8.1 and couchdb v1.0.2
My map function is:
function(doc) {
emit(doc.doc_type, 1);
}
My…

Up.
- 959
- 11
- 20
14
votes
1 answer
Using map reduce in CouchDB to output fewer rows
Lets say you have two document types, customers and orders. A customer document contains basic information like name, address etc. and orders contain all the order information each time a customer orders something. When storing the documents, the…

Matt
- 1,811
- 1
- 19
- 30
14
votes
4 answers
What do the Stream reduce() requirements exactly entail?
When using the reduce() operation on a parallel stream, the OCP exam book states that there are certain principles the reduce() arguments must adhere to. Those principles are the following:
The identity must be defined such that for all elements…

Maurice
- 6,698
- 9
- 47
- 104
14
votes
7 answers
Split array into two different arrays using functional JavaScript
I was wondering what would be the best way to split an array into two different arrays using JavaScript, but to keep it in the realms of functional programming.
Let's say that the two arrays should be created depending on some logic. For instance…

Jan Swart
- 6,761
- 10
- 36
- 45
14
votes
5 answers
How do you apply 'or' to all values of a list in Python?
How do you apply 'or' to 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])

Pablo Fernandez
- 279,434
- 135
- 377
- 622
14
votes
3 answers
Fold/reduce over List of Futures with associative & commutative operator
Consider the following:
import scala.concurrent._
import scala.concurrent.duration.Duration.Inf
import scala.concurrent.ExecutionContext.Implicits.global
def slowInt(i: Int) = { Thread.sleep(200); i }
def slowAdd(x: Int, y: Int) = {…

Erik Kaplun
- 37,128
- 15
- 99
- 111
14
votes
3 answers
pickle cython class
I have to save and load a cython class instance.
My cython class is this plus several methods:
import numpy as np
cimport numpy as np
cimport cython
cdef class Perceptron_avg_my:
cdef int wlen,freePos
cdef np.ndarray w,wtot,wac,wtotc…

Francesco
- 323
- 1
- 2
- 10