Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
3 answers
100 views

Accessing a class member inside another another class from a Python Lambda expression

I cannot understand why I cannot reference the integer member of the nested class in the lambda. The following code demonstrates the failure. The same reference is used in the print prior to the ...
Tarthalion's user avatar
3 votes
2 answers
125 views

How to make a `functools.reduce` implementation that looks similarly as `Reduce` in R?

Here is an R example of using Reduce x <- c(1, 2, 2, 4, 10, 5, 5, 7) Reduce(\(a, b) if (tail(a, 1) != b) c(a, b) else a, x) # equivalent to `rle(x)$values` The code above is to sort out the ...
ThomasIsCoding's user avatar
0 votes
0 answers
73 views

Skewness and kurtosis for image processing

While running python map reducing code to calculate skewness and kurtosis values i am unable to get output: Code import os from mrjob.job import MRJob from scipy.stats import skew, kurtosis import ...
Suneel Kumar's user avatar
-1 votes
1 answer
79 views

Applying a function to all elements of a tree in Python

There is a tree-like data structure, the nodes of which contain scalar values (integers), lists and dictionaries, np.array. I need to write a function (in Python) that applies an aggregation function ...
Kwas's user avatar
  • 7
0 votes
1 answer
167 views

Most Pythonic way to handle exception caused by functools.reduce when the iterable yields no elements?

Python's functools.reduce throws an exception when the iterable passed to it yields no elements. Here's how I currently use it: some_list = [] # empty list should be permissible functools.reduce( ...
user2138149's user avatar
  • 17.9k
2 votes
0 answers
114 views

MapReduce Troubleshoot with python script as mapper and reducer using hadoop-streaming-3.3.6.jar

core-site.xml config : <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://Master:9000</value> </property> </...
Mohamed MOUHNARI's user avatar
1 vote
3 answers
109 views

Given a list of lists of two timestamps, how to check if the index of a dataframe is inside those datetime range?

I have a list of lists of two elements with type pd.Timestamp, e.g.: intervals = [ [pd.Timestamp('2023-01-01 02:00:00'), pd.Timestamp('2023-01-01 03:00:00')], [pd.Timestamp('2023-01-01 05:00:...
LucaM's user avatar
  • 77
0 votes
1 answer
64 views

How does reduceByKey() in pyspark knows which column is key and which one is value?

I'm a newbie to Pyspark and going through this. How does reduceByKey() know whether it should consider the first column as and second as value or vice-versa. I don't see any column name or index ...
Underoos's user avatar
  • 5,230
-1 votes
1 answer
117 views

naive cuda kernel for ReduceL2 operator

I am trying to implement a cuda kernel for the operator ReduceL2 for educational purpose. For example, I have a 3-d tensor with shape 400*500*256 and it should be 'l2'-reduced along the first and ...
user9875189's user avatar
0 votes
2 answers
157 views

Multiprocessed reduce function hangs when task queue size of above 1200 elements in Python

the program works fine untill the size of the to_sum list reaches about 1150. Afterwards, the processes will hang at the first point where task_queue = result_queue. They will successfully fill the ...
Tary's user avatar
  • 103
0 votes
1 answer
93 views

How do I reduce a list of tuples into one output?

I just completed a mapper and groupby script. Running it in my terminal gives me a list of tuples: a [('1', '0', '0'), ('1', '1', '1')] b [('1', '0', '0')] e [('1', '0', '0'), ('1', '0', '1')] f [('1',...
Zaku's user avatar
  • 158
0 votes
1 answer
65 views

How to reduce the length of this code written with python.turtle?

I need help reducing the total length or lines of this code written with python.turtle. I need to have the same output and just reduce the length of the lines if possible using other functions! Here ...
ggpython's user avatar
0 votes
1 answer
83 views

Understanding Unusual Behavior in Python's functools.reduce() Function with Custom Reducer Function

I've been working on a Python project that requires the use of the functools.reduce() function. I came across an unusual behavior when using a custom reducer function, and I am unable to figure out ...
user avatar
3 votes
1 answer
169 views

Error: 'int' object is not subscriptable - when using lambda in reduce function

When running the following code, I get the following Error: Traceback (most recent call last): File "/Users/crosseyedbum/Documents/Visual Studio Code/Fundamentals of Python_5.py", line 127,...
not_like_theketchup's user avatar
1 vote
1 answer
117 views

python reduce return function reference and not the value of the function

Learning Python. I was learning reduce() and was playing with the initialization parameter. The code simply outputs a SHA256 hash of a list of strings. At first I used a for loop to generate the ...
OldProgrammerLearningNewTricks's user avatar

15 30 50 per page
1
2 3 4 5
26