Questions tagged [enumerate]

Related to functions or methods that return enumerations or enumerated-types. These can be objects, data types or data structures in which each of the items of a set has a one-to-one correspondence with a set of ordered numbers. An example is the `enumerate()` built-in function in Python.

Related to functions or methods that return enumerations or enumerated-types. These can be objects, data types or data structures in which each of the items of a set has a one-to-one correspondence with a set of ordered numbers. An example is the enumerate() built-in function in Python.

In Python, the function enumerate(sequence, start=0) sequence must be an object which supports iteration. enumerate() returns an enumerate object which consists of tuples containing a count (from start) and the values obtained from iterating over sequence (from the Python Standard Library official documentation)

975 questions
3
votes
1 answer

PyTorch custom dataset dataloader returns strings (of keys) not tensors

I am trying to load my own dataset and I use a custom Dataloader that reads in images and labels and converts them to PyTorch Tensors. However when the Dataloader is instantiated it returns strings x "image" and y "labels" but not the real values or…
dusa
  • 840
  • 3
  • 14
  • 31
3
votes
2 answers

how to find index of min and max value of a int array Python

Hello I want to find the first index of the max and min value of an array of integer. my code returns all the index in case of duplicate values ... A= [1,1,8,7,5,9,6,9] def minmaxloc(num_list): for i,y in enumerate(num_list): if y…
bryan tetris
  • 123
  • 1
  • 3
  • 7
3
votes
1 answer

Is there a standard way of enumerating allocated heap blocks in Linux?

In windows, I've used Heap32ListFirst / Heap32ListNext to iterate over the heaps list, and then for each heap I'd use Heap32First / Heap32Next to get every block. Is there an equivalent way of doing so in Linux, glibc or otherwise? I couldn't find…
Kinetic
  • 55
  • 5
3
votes
3 answers

Sort an enumerated list by the value

MWE: list1 = [2,5,46,23,9,78] list1 = list(enumerate(list1)) Now suppose I want to sort this list by the index 1, i.e. by the original list1, in say, ascending order. How do I do that? I would like something that could then give me both the indexes…
Euler_Salter
  • 3,271
  • 8
  • 33
  • 74
3
votes
1 answer

Enumerate records sequentially, grouped and by date, in MySQL

This seems like such a simple question and I terrified that I might be bashed with the duplicate question hammer, but here's what I have: ID Date 1 1/11/01 1 3/3/03 1 2/22/02 2 1/11/01 2 2/22/02 All I need to do is enumerate the records,…
Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
3
votes
2 answers

Fast bit string generation given indices

Here a is a list, for example [34, 52, 57]. The function takes in this list and creates a bit string of length 64, where every index is a 0 except at the given indices. So it would look like [0,0,....1,...1,..1,..0,0,0] where only at indices [34,…
Vajjhala
  • 160
  • 1
  • 15
3
votes
3 answers

Python: How to do nested enumerate for loop?

I have two files, file1 and file2, and for every file1 line, I’m trying to check against all the lines of file2. So I did a nested enumerate for loop, but checking the first line of file1 against all the lines of file2, the program just completes,…
Jo Ko
  • 7,225
  • 15
  • 62
  • 120
3
votes
4 answers

Print specific lines of multiple files in Python

I have 30 text files of 30 lines each. For some reason, I need to write a script that opens file 1, prints line 1 of file 1, closes it, opens file 2, prints line 2 of file 2, closes it, and so on. I tried this: import glob files =…
3
votes
1 answer

latex enumerate custom numerical order

are there any simple: almost a single liner latex commands to make enumerate count in a weird order for instance that of a homework assignment? Ex. 1, 5, 6, 9, 10, 13, 16
GlassGhost
  • 16,906
  • 5
  • 32
  • 45
3
votes
1 answer

Iterate Across Columns in a List of Lists in Python

When I attempt iteration across columns in a row, the column does no change within a nested loop: i_rows = 4 i_cols = 3 matrix = [[0 for c in xrange(i_cols)] for r in xrange(i_rows)] for row, r in enumerate(matrix): for col, c in enumerate(r): …
noumenal
  • 1,077
  • 2
  • 16
  • 36
3
votes
3 answers

Enumerate function

Can someone explain this to me. So, I have a list s with numbers from -1 to 1 and I want to extract position of certain numbers in a list. Example: s= [-1, 0.5, 0.2, -0.9] z = enumerate(s) y1 = [] for i,j in z: if j<=-0.8 and j>=-1: k =…
VlS
  • 586
  • 3
  • 13
3
votes
3 answers

Sorting lists by column

At the moment I am trying to sort a file with data such as: [Name] [Score] [Name] [Score] And this goes on. I am trying to sort it by score. So my method is to get all the data from a file and sort it. However I use the sort function and it…
Reece
  • 29
  • 4
3
votes
2 answers

How can I zip together two very large strings and return indices for matches and mismatches?

I have a set of text files which contain two very large sets of characters of identical length. The sets of characters are DNA sequences so I'm going to call them seq_1 and seq_2 and together they are called an alignment. Files look like…
isosceleswheel
  • 1,516
  • 12
  • 20
3
votes
2 answers

Adding first occurrence in a 2D list to another list (Python 3.4.2)

This is currently my code: num = 0 sav = [["Name: ", "Josh", "Score", "1"], ["Name", "James", "Score: ", "2"], ["Name: ", "Josh", "Score: ", "2"]] sav2 = [[]*5 for _ in range(len(sav)] name2 = sav[num][1] for i, j in enumerate(sav2): if name2…
3
votes
3 answers

Enumerate Dictionary Within ASP.NET Web Page

I have a ASP.NET (C#) web page in which I want to enumerate a dictionary in a code render block: <% foreach (Dictionary record in parsedData) { %>
...Some HTML Code...
<% } %> But I get an error like: Compiler Error…
joshwbrick
  • 5,882
  • 9
  • 48
  • 72