Answer the question
In order to leave comments, you need to log in
How to correctly get the element number of a multidimensional array?
Good afternoon!
I'm still trying to figure out how to get the element number of a multidimensional array.
The piece of code where it applies:
mls_scc = LearnMaxLevelDataArray("school")
for rowm, index in mls_scc:
if row['gender'] == "M":
input_ssc_level = rd[rowm[1][0].index(index)].value
if row['gender'] == "F":
input_ssc_level = rd[rowm[0][0].index(index)].value
maxlevelbalance = 100 - input_ssc_level #Получает баланс уровня от максимального уровня критерии
userlevelbalance = 100 - row['ssc_p']
if maxlevelbalance > userlevelbalance:
levelbalance = maxlevelbalance - userlevelbalance #Подсчитываем баланс от уровня
if maxlevelbalance < userlevelbalance:
levelbalance = userlevelbalance - maxlevelbalance
for rowms, index in mlsb.iterrows():
if levelbalance == rowms[index] or levelbalance > rowms[index]:
#Если текущий баланс уровня соответствует нужным критериям, то система для списка успешных выпускников оставит уровень школьных знании, которого добился выпускник
sgl['profile']['info']['school'] = row['ssc_p']
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
43
44 if row['gender'] == "M":
---> 45 input_ssc_level = rd[rowm[1][0].index(index)].value
46 if row['gender'] == "F":
47 input_ssc_level = rd[rowm[0][0].index(index)].value
TypeError: must be str, not list
Answer the question
In order to leave comments, you need to log in
TypeError: must be str
It requires the function to be a list
for index, rowm in enumerate(mls_scc):
if row['gender'] == "M":
input_ssc_level = rd[rowm[1][0].index(index)].value
if row['gender'] == "F":
input_ssc_level = rd[rowm[0][0].index(index)].value
We made it up, of course) You have a main list da it consists of 2 objects, you call the for loop which goes through 2 objects, respectively, the variables rowm, index are two separate non-intersecting lists. Briefly speaking
input_ssc_level = rd[>>>>rowm[1][0].index(index)<<<<].value
rowm[1][0] - you are not accessing the list, but the text, more precisely, even the letter of the text, and after that you try to call the index method on it by passing the list
If a is a multidimensional array, and x is the value of the array whose index you want to find, then you can do this.
import numpy as np
indeces = np.unravel_index((a == x).argmax(), a.shape)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question