0

I'm trying to build my first intrusion detection system using fuzzy adaptive resonance theory and when i try the following code it gives me a type error (map is not subscriptable) and i already revised the previous same question like mine but i couldn't solve it and here is my code fragment, thanks.

len1 = len(categoryList)
    for i in range(len(train_data_pca_df2)):
        tjList = []
        for j in range(len(categoryList)):
            tjList.append((j, sum(fuzzyAnd(train_data_pca_df2[i], categoryList[j]))/(alpha+sum(categoryList[j]))))
        tjList = sorted(tjList, key=lambda item:item[1])
        noMatchFlag = True
        while len(tjList) != 0 :
            (index, value) = tjList.pop(0)
            if sum(fuzzyAnd(train_data_pca_df2[i], categoryList[index]))/sum(train_data_pca_df2[i]) >= rho :
                categoryList[index] = map(lambda x, y: x*beta + y*(1-beta),
                                          fuzzyAnd(train_data_pca_df2[i], categoryList[index]), categoryList[index])
                noMatchFlag = False
                break
        if noMatchFlag:
            categoryList.append(train_data_pca_df2[i])

and here's my traceback

TypeError                Traceback (most recent call last)
<ipython-input-23-433f62c5405b> in <module>()
     23         tjList = []
     24         for j in range(len(categoryList)):
---> 25             tjList.append((j, sum(fuzzyAnd(train_data_pca_df2[i], categoryList[j]))/(alpha+sum(categoryList[j]))))
     26         tjList = sorted(tjList, key=lambda item:item[1])
     27         noMatchFlag = True

<ipython-input-1-9abb94d46c1b> in fuzzyAnd(tuple1, tuple2)
     40     ls = []
     41     for i in range (len(tuple1)):
---> 42         ls.append(min(tuple1[i], tuple2[i]))
     43     return ls
     44 

TypeError: 'map' object is not subscriptable
ziadx123
  • 1
  • 1
  • 1
    Possible duplicate of [Add new keys to a dictionary?](https://stackoverflow.com/questions/1024847/add-new-keys-to-a-dictionary) – jordiburgos Mar 07 '18 at 19:45
  • Please provide a [mcve]. However, your error message seems pretty clear, you are trying to index into a `map` object, but `map` objects don't support indexing. – juanpa.arrivillaga Mar 07 '18 at 19:57

1 Answers1

0

The map function returns an object and not a list. You are assigning a map object to a list variable categoryList[index]. If you want to return a list, call list(map(...)) and then assign it to the list variable categoryList[index].

amanb
  • 5,276
  • 3
  • 19
  • 38