Search code examples
pythondatabasenumpyfor-loopdata-analysis

The problem of double for loop with data change in python


I have 100 input data line, and as you can see I try to change the value of the input data by using the 'for loop'. Consequently, my model calculates 100*6 times. Also, I want to see the minimum value of each time step(data line) and get the minimum 'dat' value index (totally I want to see the 100 number of minimum dat value).

realdata_file = open("C:/","r")
realdata_list = realdata_file.readlines()
realdata_file.close()
dat = [12,13,14,15,16,17]

for record in realdata_list:
    all_values = record.split(',')
    inputs_list = (numpy.asfarray(all_values[1:]))
    get_list = []
    get_min = []
    get_mindat = []
    for h in dat:
        inputs_list[1] = h
        output = (n.query(inputs_list)
        output = output.tolist()
        get_list.extend(output[0])
        get_min = min(get_list)
        get_mindat = get_list.index(min(get_list))
        print(get_list)



output = (n.query(inputs_list) means that return numpy array by using input_list

However, when I run my code, I got these results from get_list. These are part of my results.

[0.384307]
[0.384307, 0.384488]
[0.384307, 0.384488, 0.385094]
[0.384307, 0.384488, 0.385094, 0.385982]
[0.384307, 0.384488, 0.385094, 0.385982, 0.387043]
[0.384307, 0.384488, 0.385094, 0.385982, 0.387043, 0.388196]

How can I only get the last line? I mean includes six data :(


Solution

  • Unindent the print(get_list) so it runs after the loop instead of at the end of each loop.