Questions tagged [functools]

functools is a module for the Python language which provides support for working with higher-order functions: functions that act on or return other functions

functools is a module for the Python language which provides support for working with higher-order functions: functions that act on or return other functions.

The official documentation can be found here: here

382 questions
0
votes
2 answers

Create a function object from a function and a partial function

I am new using function generators. I am working with the following function: def math_model(n: float): def crrcn(x, t0: float, amp: float, tau: float, offset: float, dt: float, k: float): crrcn = np.zeros(np.shape(x)) for i, a…
xikhari
  • 99
  • 3
  • 14
0
votes
1 answer

i want to take a value from entry but that didn't work

the problem is: return self.func(*args) TypeError: b1_pg() missing 1 required positional argument: 'e1' i search entire google but i didn't found any thing from tkinter import * from tkinter import ttk from functools import partial root =…
0
votes
1 answer

How to call Python partial without using parentheses?

Suppose the code below: from functools import partial import random def integer(min=1, max=10): return random.randint(min, max) def double(min=1, max=10): return random.uniform(min, max) if __name__ == '__main__': p1 =…
user1330974
  • 2,500
  • 5
  • 32
  • 60
0
votes
0 answers

ImportError: No module named functools ( Windows 10)

I am getting below error while running Python Batch in Win10 Python2.7. The same batch was previously running in Win7. C:/Users/Chris/.platformio/penv/lib/python2.7/site.py", line 703, in…
user11664493
  • 3
  • 1
  • 2
0
votes
3 answers

Unexpected results with functools reduce in python

While executing the below code I'm simply getting the first row(split) of the matrix back not the sum of the elements as what I'm expecting. Is my understanding incorrect or did I do something stupid? My objective is to get the sum of all elements…
Codistan
  • 1,469
  • 1
  • 13
  • 17
0
votes
3 answers

python flatten an array of array, why funtools is slower?

based on this question python flatten an array of array I want a faster way than the double loop solution. so I write a functools based function,but it seems much slower. orders2.shape (9966, 1) import time t0 = time.time() [x for i in…
Tommy Yu
  • 1,080
  • 3
  • 11
  • 30
0
votes
1 answer

Sorting a list of class objects using conditions in class parameters

I have a list of objects instantiated from a class. I need to sort the list using 'x' and 'is_start' parameters. I tried using the total_ordering module from functools and custom wrote the lt & eq methods. Class: @total_ordering class…
Adda
  • 23
  • 3
0
votes
1 answer

chain join multiple arguments from a list of variable size using a supplied bivariate function

I am looking to execute a function over all arguments in a list (map could do that part) and then "join" them using another function that could be exited early (say if the objective was to find an instance or reach a threshold). Here is an example…
crogg01
  • 2,446
  • 15
  • 35
0
votes
1 answer

using reduce to calculate gini index for a node

I am trying to apply the formula: I am unclear why this does not work: def gini_node(node): count = sum(node) gini = functools.reduce(lambda p,c: p + (1 - (c/count)**2), node) print(count, gini) print(1 - (node[0]/count)**2, 1 -…
roberto tomás
  • 4,435
  • 5
  • 42
  • 71
0
votes
1 answer

How to write a wrapper to fix arbitrary parameters of the jacobian of a function

This is an extension of a previous stack-exchange question I posted. link Context: My goal is to fit data to a function f(t, *p) using the scipy.optimize.curve_fit function. I happen to know some parameters pfix = {p_j, ..., p_k} and want to fit…
firest
  • 57
  • 7
0
votes
1 answer

cannot install functools32 on google colab

I'm new to ML/DL and using google colab as my DL tool. I'm currently trying to setup tensorflow/HED on google colab. When I ran pip install -r requirements.txt, I got an error like Collecting functools32==3.2.3.post2 (from -r requirements.txt (line…
0
votes
0 answers

Save partial function call in json file

I have a dictionary to store N number of partial function calls. dict_ = {1: partial(FUNCTION, ARG1,ARG2,ARG3 )} which works fine. If I store this dictionary inside a .json file I have quotes around my partial call dict_ = …
user2963882
  • 625
  • 1
  • 8
  • 19
0
votes
1 answer

Itertools.accumulate to find union of intervals (convert from reduce to accumulate)

I seem to have developed the right reduce operation to find the union of intervals, only to realize that reduce gives you a final result. So I looked up the documentation and figured out that what I should be using is in fact accumulate. I need…
ababuji
  • 1,683
  • 2
  • 14
  • 39
0
votes
1 answer

Accessing keyword argument of decorated function inside the decorator fails in Python 3

kwargs is empty in the following code. How to access timeout keyword arg of the decorated function? import functools def retriable(func): @functools.wraps(func) def wrapper(*args, **kwargs): timeout = kwargs['timeout'] …
rok
  • 9,403
  • 17
  • 70
  • 126
0
votes
1 answer

Return a function object with wrapper

I have a complex library, which users can add functions to. This library is then used in a program which then accepts input. Problem is, the functions aren't being processed the way I want them to. Let me illustrate (I've simplified the code to…
Code Monkey
  • 800
  • 1
  • 9
  • 27