I am completely new to the topic of programming but interested. I am coding in python 3.x and have a question to my latest topic:
We have a list, containing a few tenthousands of randomly generated integers between 1 and 7.
import random
list_of_states = []
n = int(input('Enter number of elements:'))
for i in range(n):
list_of_states.append(random.randint(1,7))
print (list_of_states)
Afterwards, I would like to count the contiguous numbers in this list and put them into an numpy.array
example: [1, 2, 3, 4, 4, 4, 7, 3, 1, 1, 1]
1 1
2 1
3 1
4 3
7 1
3 1
1 1
I would like to know whether someone has a hint/an idea of how I could do this. This part is a smaller part of a markov chain wherefor I need the frequency of each number.
Thanks for sharing Nadim
Aucun commentaire:
Enregistrer un commentaire