I am using Python 2.7 and started learning Python several days ago. I am still trying to get my head around how Python indexes arrays. The arrays start at zero instead of one. I am practicing on manipulating arrays around and could use some help.
I have 2 arrays - A
and B
- and I want to get the value in B
that is parallel to the value in A
.
Below is the code that I am messing around with to help me get proficient with arrays:
A = [2, 8, 29, 34, 54, 61, 73, 89, 97, 101]
B = [201, 309, 454, 540, 602, 750, 889, 973, 1003, 1120]
B[2] = 454
# B[2] = 201 this is what I want
B[8] = 1003
#B[8] = 309 this is what I want
Both arrays are the same length, but as you can see, I am trying to work on the indexing. If I just do B[A], its an out of bounds index error code. I tried using:
A.searchsorted(B) #but still get an error.
I am not sure if I am making any sense, as I know what I want in my head but just can't get the correct wording out to make it easier. Hopefully the example above shows what I am wanting. The only thing I have found on the site is the searchsorted (maybe I am using it incorrectly). This method was brought to my attention from a previous question and I looked further into it, but still can't find what I am looking for.