jeudi 23 mars 2017

How to access values from a multidimensional array with a for loop?

I have created an IF statement tree to give sets of data in arrays a label. The multidimensional array is called featureVectors and numberOfSides, standardDeviationsPerimeter, standardDeviationsAngles(not used in this section of code) and largestAngles are all arrays included in the array. I want to pass all the arrays in featureVectors through the IF statement but it doesn't loop past the first one therefore giving every dataset the label 2. I am not very good at loops with multidimensional arrays.This is my code so far:

for shape in range(0, len(sidesDividedByPerimeter)):
    if numberOfSides[0] == 1:
       labels = 0
    elif numberOfSides[0] > 1 and numberOfSides[0] < 3.5:
       labels = 1
    elif numberOfSides[0] > 3.5:
       if standardDeviationsPerimeter[0] < 0.1458:
           if largestAngles[0] < 104.79:
              labels = 2
           elif largestAngles[0] >= 104.79:
              labels = 3
    elif standardDeviationsPerimeter[0] >= 0.1458:
           labels = 4

    print(featureVectors)
    print(labels)
    #featureVectors[shape].append(labels)

This gives me the output:

I just need it to run through each of the arrays instead of stopping at the first. I know its because of my [0]'s but i just dont know what I should do, im only learning python.

Aucun commentaire:

Enregistrer un commentaire