I’ve generated a graph of random numbers (standard deviation 1, mean 0). I need to run through the list and print out each number if it is the biggest one currently seen. For example, given the list [10, 5, 15, 18, 5, 7, 9, 100], the code would print out:
10 (first number is always going to be the biggest currently seen)
15
18
100
Here’s my code:
import pylab
a = pylab.arange(1.0, 129.05, 1)
xrandn = pylab.zeros(129, float)
for j in range(0, 129):
xrandn[j] = pylab.randn()
pylab.plot(a, xrandn, "r-")
pylab.xlabel("Year")
pylab.ylabel("Units")
pylab.title("Possible Tempertaure Fluctuations")
pylab.show()
Also, as an extra, how could I mark these points on the graph itself?
Edit 1:
thanks for your replies, im now stuck on the following
I now need to generate a large number of random number “sets” from which I need to be able to retrieve the maximum value of the first value in every set and there after be able to access the second value of every set, then the third in every set etc counting the numbers of values that exceed the previous maximum. I have tried creating a matrix to do this for me, however I keep getting the error message telling me I cant use floating numbers within a matrix, and I am now unsure if this is the correct method or if some sort of amendment to the previous code will yield the answer .
import pylab
def make_list(size):
"""create a list of size number of zeros"""
mylist = []
for i in range(size):
y = pylab.randn()
mylist.append(y)
return mylist
def make_matrix(rows, cols):
"""
create a 2D matrix as a list of rows number of lists
where the lists are cols in size
resulting matrix contains zeros
"""
matrix = []
for i in range(rows):
matrix.append(make_list(cols))
return matrix
mx = make_matrix(10, 6)
print(mx)
As simple as it can be