Questions tagged [variable-length]

Refers to anything whose length can vary

Refers to anything whose length can vary

290 questions
449
votes
10 answers

Why aren't variable-length arrays part of the C++ standard?

I haven't used C very much in the last few years. When I read this question today I came across some C syntax which I wasn't familiar with. Apparently in C99 the following syntax is valid: void foo(int n) { int values[n]; //Declare a variable…
Andreas Brinck
  • 51,293
  • 14
  • 84
  • 114
89
votes
6 answers

How to find the length of a "filter" object in python

>>> n = [1,2,3,4] >>> filter(lambda x:x>3,n) >>> len(filter(lambda x:x>3,n)) Traceback (most recent call last): File "", line 1, in len(filter(lambda x:x>3,n)) TypeError: object of…
Srichakradhar
  • 1,535
  • 1
  • 12
  • 24
67
votes
2 answers

Object of type 'map' has no len() in Python 3

I have a problem with Python 3. I got Python 2.7 code and at the moment I am trying to update it. I get the error: TypeError: object of type 'map' has no len() at this part: str(len(seed_candidates)) Before I initialized it like…
Sonius
  • 1,597
  • 3
  • 14
  • 33
62
votes
4 answers

How do I create a variable-length input LSTM in Keras?

I am trying to do some vanilla pattern recognition with an LSTM using Keras to predict the next element in a sequence. My data look like this: where the label of the training sequence is the last element in the list:…
erip
  • 16,374
  • 11
  • 66
  • 121
42
votes
4 answers

Why does len() returned a signed value?

Go's builtin len() function returns a signed int. Why wasn't a uint used instead? Is it ever possible for len() to return something negative? As far as I can tell, the answer is no: Arrays: "The number of elements is called the length and is never…
daxelrod
  • 2,499
  • 1
  • 22
  • 30
41
votes
3 answers

javascript object max size limit

I'm trying to pass a JavaScript variable to the server-side using jquery.ajax method. I'm trying to create a json string, but when the length of variable reaches 10000, no more data is appended to the string. var jsonObj = '{"code":"' + code +…
Paras
  • 2,997
  • 6
  • 35
  • 46
26
votes
3 answers

How does Pytorch Dataloader handle variable size data?

I have a dataset that looks like below. That is the first item is the user id followed by the set of items which is clicked by the user. 0 24104 27359 6684 0 24104 27359 1 16742 31529 31485 1 16742 31529 2 6579 19316 …
Trung Le
  • 443
  • 1
  • 4
  • 10
25
votes
4 answers

Matrix of unknown length in MATLAB?

I'm trying to set up a zero matrix of variable length with two columns into which I can output the results of a while loop (with the intention of using it to store the step data from Euler's method with adjusted time-steps). The length will be…
Flick
  • 253
  • 1
  • 3
  • 4
24
votes
11 answers

Finding whether a string starts with one of a list's variable-length prefixes

I need to find out whether a name starts with any of a list's prefixes and then remove it, like: if name[:2] in ["i_", "c_", "m_", "l_", "d_", "t_", "e_", "b_"]: name = name[2:] The above only works for list prefixes with a length of two. I…
Kawu
  • 13,647
  • 34
  • 123
  • 195
22
votes
3 answers

Are variable length arrays possible with Javascript

I want to make a variable length array in Javascript. Is this possible. A quick google search for "Javascript variable length array" doesn't seem to yield anything, which would be surprising if it were possible to do this. Should I instead have a…
Ankur
  • 50,282
  • 110
  • 242
  • 312
21
votes
11 answers

Variable Sized Struct C++

Is this the best way to make a variable sized struct in C++? I don't want to use vector because the length doesn't change after initialization. struct Packet { unsigned int bytelength; unsigned int data[]; }; Packet* CreatePacket(unsigned…
Unknown
  • 45,913
  • 27
  • 138
  • 182
15
votes
3 answers

len() of a numpy array in python

If I use len(np.array([[2,3,1,0], [2,3,1,0], [3,2,1,1]])), I get back 3. Why is there no argument for len() about which axis I want the length of in multidimensional arrays? This is alarming. Is there an alternative?
Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
15
votes
1 answer

What is the advantage of having instructions in a uniform format?

Many processors have instructions which are of uniform format and width such as the ARM where all instructions are 32-bit long. other processors have instructions in multiple widths of say 2, 3, or 4 bytes long, such as 8086. What is the advantage…
15
votes
1 answer

MVC 4 - More Elegant way to Edit Variable-Length List of Items?

The best advice I found for editing a variable-length list of items was written for ASP.Net MVC 2 in 2008. http://blog.stevensanderson.com/2008/12/22/editing-a-variable-length-list-of-items-in-aspnet-mvc/ Is that approach still the best one for…
Eric J.
  • 147,927
  • 63
  • 340
  • 553
13
votes
16 answers

Most compact way to encode a sequence of random variable length binary codes?

Let's say you have a List> and you want to encode that into binary form in the most compact way possible. I don't care about read or write performance. I just want to use the minimal amount of space. Also, the example is in Java, but…
Pyrolistical
  • 27,624
  • 21
  • 81
  • 106
1
2 3
19 20