0
votes

I'm getting an index error: "IndexError: index 2 is out of bounds for axis 1 with size 2"

explanation: using numpy, say I have np.Array[(a(1),b(1)) , (a(2),b(2)) ...]. I'm trying to print every b(n) in np.Array.

What's happening is, the program outputs every a(n), then every b(n) on separate lines.

my code:

k = np.array([["words words ", 3], ["blah blah", 1], [" please help me", 9]])

for i in range(len(k)):
        print(k[:,i])
1
Because the length of k is 3 and each of your sub lists have only two elements. If you want to print the last element of each sublist, use print(k[i][-1]). - Sheldore

1 Answers

0
votes

do

k = np.array([["words words ", 3], ["blah blah", 1], [" please help me", 9]])

for i in range(len(k)):
    print(k[i,1])