Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
np.array question
#1
Morning all,

I am a python beginner and was playing around.

I ran into a roadblock when the original np.array was set up to use a 9 varriable array like below...

adjacent_facies = np.array([[1], [0,2], [1], [4], [3,5], [4,6,7], [5,7], [5,6,8], [6,7]])
and I need to convert it for a 6 variable breakdown and get an index error...

IndexError: index 6 is out of bounds for axis 0 with size 6

Any help would be appreciated as I do not really understand the np.array functionality fully yet.

Thanks,

-RH
Reply
#2
you don't show your code (always do, in python tags)
indexes are 0 based, so for array of size 6 max index is 5
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Apr-19-2020, 01:51 PM)buran Wrote: you don't show your code (always do, in python tags)
indexes are 0 based, so for array of size 6 max index is 5

Apologies here is the code

# define our accuracy
def accuracy(conf):
    total_correct = 0.
    nb_classes = conf.shape[0]
    for i in np.arange(0,nb_classes):
        total_correct += conf[i][i]
    acc = total_correct/sum(sum(conf))
    return acc
# Define error within 'adjacent facies'
#This needs to be updated for 6 facies model ,np.array -RH
adjacent_facies = np.array([[1], [0,2], [1], [4], [3,5], [4,6,7], [5,7], [5,6,8], [6,7]])

def accuracy_adjacent(conf, adjacent_facies):
    nb_classes = conf.shape[0]
    total_correct = 0.
    for i in np.arange(0,nb_classes):
        total_correct += conf[i][i]
        for j in adjacent_facies[i]:
            total_correct += conf[i][j]
    return total_correct / sum(sum(conf))

#display accuracy
print('Facies classification accuracy = %f' % accuracy(conf))
print('Adjacent facies classification accuracy = %f' % accuracy_adjacent(conf, adjacent_facies))
Reply
#4
Solved after some research,

here is what I got working.

adjacent_facies = np.array([[1], [0,3], [1], [0,3], [1], [1], [1], [5], [3]])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  meta array question meems 5 4,607 Jan-21-2017, 05:17 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020