Questions tagged [argument-unpacking]
Use this tag for questions related with argument unpacking, a technique that allows Arrays and Traversable objects to be extracted/unpacked into argument lists/sequences.
argument-unpacking
148
questions
-2
votes
1
answer
69
views
Whether, when, and why use numpy.random.rand(…) and numpy.random.random(…)?
In my understanding, if you need only one pseudorandom number in the interval [0,1[, you can use either of numpy.random.rand() and numpy.random.random(). If you need more numbers in some form, let's ...
3
votes
2
answers
82
views
Is it possible to unpack/destructure class attributes into variables?
I'm using P5.js, but the question is applicable to Javascript in general
In p5.js we have a class p5.Vector which is useful to manipulate vectors, since it already implements a variety of methods for ...
9
votes
1
answer
326
views
how to define in C++20 a concept to check if a type matches any of the types in a type-list
I want to define a concept in C++ (<= C++20) to check if a type matches any of the types define in a type-list struct.
The following is my attempt so far:
template<typename... Types>
struct ...
0
votes
2
answers
981
views
Got an unexpected keyword argument, genuinely stumped [duplicate]
I've got the following code. I'll include only the problematic bits:
class C:
def __init__(self,**kwargs):
self.kwargs = kwargs
def fit(...):
...
c = self.learner(**...
2
votes
1
answer
107
views
C++ Variadic Template Unpacking
Given the following code:
void foo(int x, int y, int z, int u)
{
}
template<typename... Args> class A;
template<> class A<>{};
template<typename T, typename... Args>
class A&...
4
votes
1
answer
255
views
How to "pack" a variable amount of outputs from a function in Lua?
I have a function in Lua that gives a variable number of outputs. How can I get all its outputs, regardless of how many outputs it has?
function my_function()
-- whatever
end
outputs_list = ...
5
votes
3
answers
95
views
Unpack variadic template to initializer_list and call two functions at once
I have two vectors:
std::vector<int> v1{ 1, 2, 3 };
std::vector<int> v2{ 4, 5, 6 };
I want to create an object of std::initializer_list which holds iterators to the first and last ...
2
votes
1
answer
182
views
How can I unpack variadic template, so as to initialize respective members?
I am new to variadic templates and packed arguments and all.
I want to have a "entity component system" in my program, and while trying to add component to the entity, I came to realize that ...
0
votes
0
answers
30
views
Return a reference to unpacked dictionary in Python
There is a common way to pass arguments in Python like this:
def foo(a1, a2):
print(a1, a2)
def my_dict():
return {'a1': 4, 'a2':5}
foo(**my_dict())
...
4 5
But now I want to move the ...
0
votes
1
answer
193
views
ValueError: too many values to unpack (expected 5) in for loop in Pandas Dataframe
I have a huge dataframe that looks like
df = pd.DataFrame([
[1, "1/1/2023", 1, 3],
[1, "1/1/2023", 2, 2],
[1, "1/1/2023", 3, 1],
[1, "1/1/2023", ...
0
votes
1
answer
63
views
print(*myVar) invalid syntax
Trying to print list items on individual lines as simply as possible following this:
https://www.geeksforgeeks.org/print-lists-in-python-4-different-ways/
>>> myVar = [1, 2, 3, 4, 5]
>>&...
0
votes
1
answer
187
views
Python : * Operator in list comprehension
Evening all,
I have recently discover the * operator to unpack my list. I find it quite elegant but I am a bit struggling with it.
Please find below an example :
from matplotlib.pyplot import Line2D
...
0
votes
2
answers
320
views
How to unpack only values from nested dict in for loop
I have the following code
mydict = {
"key": {
"k1": "v1",
"k2": "v2",
}
}
for k, (v1, v2) in mydict.items():
v1 and v2 ...
0
votes
2
answers
145
views
How to unpack a list of colons and NumPy Nones to index an array?
I am writing a program that will have an arbitrary number of : and None in arbitrary locations of an n-dimensional NumPy array. Therefore, I want a way to unpack these : and None axis operators into ...
-1
votes
1
answer
53
views
Why do I need '**' when loading json (Python) [duplicate]
t1 = Tournament("Aeroflot Open", 2010)
json_data = json.dumps(t1.__dict__)
print(json_data)
t = Tournament(**json.loads(json_data)) # <-------------------
print(f"name = {t.name}, ...