I have a 1D array. each element holds a unique value IE [2013 12 16 1 10] so array[0,0] would be [2013] array[0,1] would be [12]. array[0,0:2] would be [2013 12].
When I try array.index(array[0,0:5]). It creates error and says that list indicies must be integers, not tuple. find the index of a specific element if the element is [2013 12 16 1 10] a tuple...?
If you have a 1D array, then array[0,0] is invalid. Try this link:
Since this is a 1D array, you do:
my_array = [2013, 12, 16, 1, 10]
position for 2013 would be:
my_array[0]
I you want to do: my_array[0,0], then you need: `my_array = [[2013, 12, 16, 1, 10]]
Also check the link posted by: Musfiqur rahman
If you have a 1 dimensional array, that is simply an array of values like you mentioned where the array could equal [2013, 12, 16, 1, 10]
. You access individual items in the array by using array[index]. However, there are actually 3 parameters used for getting array values:
array[start:end:step]
array[0, 1] is invalid, as the syntax is using colons not commas. 0,1 evaluates to a tuple of 2 values, (0, 1)
. If you want to get the value of 12, you need to say array[1]
Because you are talking about a 1D array then you must do the following:
myArray = [44, 62, 2013, 2, 1, 10]
#the position for 62 would be:
myArray[1]
Then if you want to get a few values from your array you should you ":" not ",". For example:
myArray = [44, 62, 2013, 2, 1, 10]
#the position for 62, 2013, 2, 1 would be:
myArray[1:4]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.