iteration

Incrementing (iterating) between two hex values in Python

天大地大妈咪最大 提交于 2020-12-05 04:58:39
问题 I'm learning Python (slowly but surely) but need to write a program that (among other things) increments between two hex values e.g. 30D681 and 3227FF. I'm having trouble finding the best way to do this. So far I have seen a snippet of code on here that separates the hex into 30, D6 and 81, then works like this- char = 30 char2 = D6 char3 = 81 def doublehex(): global char,char2,char3 for x in range(255): char = char + 1 a = str(chr(char)).encode("hex") for p in range(255): char2 = char2 + 1 b

How to iterate over this n-dimensional dataset?

萝らか妹 提交于 2020-11-26 08:37:25
问题 I have a dataset which has 4 dimensions (for now...) and I need to iterate over it. To access a value in the dataset , I do this: value = dataset[i,j,k,l] Now, I can get the shape for the dataset : shape = [4,5,2,6] The values in shape represent the length of the dimension. How, given the number of dimensions, can I iterate over all the elements in my dataset? Here is an example: for i in range(shape[0]): for j in range(shape[1]): for k in range(shape[2]): for l in range(shape[3]): print(