Questions tagged [generator]
A generator is a generalisation of a subroutine, primarily used to simplify the writing of iterators. The yield statement in a generator does not specify a coroutine to jump to, but rather passes a value back to a parent routine.
generator
6,480
questions
0
votes
0
answers
6
views
Taking account of generator ramp constraints in pypsa optimisation
I would like to know how Pypsa handles the ramp constraints (on load, at start-up and at shutdown) of generators. Is it sufficient to fill in these attributes only or does it require additional codes?
...
2
votes
1
answer
31
views
How to save generator object to png, jpg or other image files
I'm using timeseries-generator from GitHub to get synthetic line graphs.
That works good.
But now I want to save the plots into a file as sepparate png-images.
This is my code so far:
i=range(0,4) #...
4
votes
2
answers
86
views
Reverse work out the mean using random number seed
In R language version 4.4.1 (the version should not matter, just for the sake of discussion), we write the code :
set.seed(1234)
x <- 5
y <- rnorm(1, mean = x, sd = 0.1)
We will be able to ...
3
votes
1
answer
54
views
Unexpected generator behaviour when not assigned to a variable
Could someone explain the difference between these two executions? Here is my generator function:
def g(n):
try:
yield n
print("first")
except BaseException as e:
...
5
votes
5
answers
546
views
Efficient solution for the same-fringe problem for binary trees
The fringe of a binary tree is the sequence composed by its leaves, from
left to right. The same-fringe problem [Hewitt & Patterson, 1970]
consists of determining whether two binary trees have the ...
1
vote
4
answers
94
views
Unexpected result from zipping two generators. How does zip work?
I have two generators, one which depends on the output of the other.
def do_work(n):
for i in range(n):
yield i
def more_work(x):
for i in x:
yield i * 2
def main():
x = ...
0
votes
1
answer
31
views
How do I automate dbset operations in my application?
I have a project with a large number of entities and a project that can expand further in the future. At this point, I want to automate my dbset operations. In this case, what kind of generator should ...
1
vote
2
answers
114
views
How do I check for a value efficiently in a list of dictionaries in Python?
Say I have a list of dictionaries:
universe_creatures = [
{'type': 'dragon', 'weight': 1400},
{'type': 'kraken', 'weight': 6000},
{'type': 'elf', 'weight': 75}
]
How can I search if there'...
0
votes
0
answers
18
views
How to update weights of a generator
I would like to update the weights of a stylegan generator. I have the weights delta. Is this the correct approach:
def add_weights_delta(generator, weights_delta):
with torch.no_grad():
...
0
votes
1
answer
58
views
Python, Tkinter: Apply delay to function inside generator
I am making an application in python tkinter to visualize algorithms. I want to apply a delay (window.after()) to the function partition() called inside quick_sort. The window.after() seems to only ...
0
votes
0
answers
22
views
Error in Graph Convolution Layer using StellarGraph GCN
I am trying to train a StellarGraph GCN Model and i get a dimension error on when fitting.
Below is my code.
graph = StellarDiGraph(nodes=domains, edges=edges)
generator = FullBatchNodeGenerator(graph,...
0
votes
1
answer
42
views
Why does comprehension only work with tuples when unpacking in Python?
I tried to use list comprehension on a tuple and it worked fine when unpacking, but not when assigning to a single variable.
If I run the following code
var1, var2, var3 = (i for i in range(3))
var1 =...
-3
votes
1
answer
73
views
Why the result is the same even if the variable isnt static?
char next_char(void){
char letter='a';
while(letter!='z'){
letter=letter+1;
char next_char(void);
}
printf("%c",letter);
}
When the variable letter is ...
1
vote
1
answer
31
views
calculating time of generator of generic function
Trying to calculate the time that each yield takes from any function using generator, but I cant find any way to do so.
The closest I got is creating a wrapper like this:
def ...
0
votes
1
answer
40
views
How to generate the your-class.proto from C# object with decorators
I'm using protobuf-net to serial/deserialize the data to work with my Kafka cluster.
Is there any way to generate the class-name.proto from the C# class with decorators like the one below?
Thanks
...