'long' object has no attribute '__getitem__' Error in a func

A forum for general discussion of the Python programming language.

'long' object has no attribute '__getitem__' Error in a func

Postby SKY_SHY » Sun Sep 18, 2016 9:58 am

I have a problem with my python-code.

I have an array which is called the group:

Code: Select all
import numpy as np   
group = np.array(
[[[0,0,1,0,0],
[0,1,0,1,0],
[0,1,0,1,0],
[0,1,0,1,0],
[0,0,1,0,0]],
[[0,0,1,0,0],
[0,1,1,0,0],
[0,0,1,0,0],
[0,0,1,0,0],
[0,1,1,1,0]],
[[0,1,1,0,0],
[0,1,0,1,0],
[0,0,1,0,0],
[0,1,0,0,0],
[0,1,1,1,0]],
[[0,1,1,1,0],
[0,0,1,0,0],
[0,1,1,1,0],
[0,0,0,1,0],
[0,1,1,1,0]],
[[0,0,1,1,0],
[0,1,0,1,0],
[0,1,1,1,0],
[0,0,0,1,0],
[0,0,0,1,0]],
[[0,1,1,1,0],
[0,1,0,0,0],
[0,1,1,1,0],
[0,0,0,1,0],
[0,1,1,1,0]],
[[0,0,0,1,0],
[0,0,1,0,0],
[0,1,1,1,0],
[0,1,0,1,0],
[0,1,1,1,0]],
[[0,1,1,1,0],
[0,0,0,1,0],
[0,0,1,0,0],
[0,1,0,0,0],
[0,1,0,0,0]],
[[0,1,1,1,0],
[0,1,0,1,0],
[0,0,1,0,0],
[0,1,0,1,0],
[0,1,1,1,0]],
[[0,1,1,1,0],
[0,1,0,1,0],
[0,1,1,1,0],
[0,0,1,1,0],
[0,1,0,1,0]]])
>
dataSetSize = group.shape[0]
>
a1=[
[1 1 0 1 0] 
[0 0 0 0 0] 
[0 0 1 1 1] 
[1 0 1 0 1] 
[0 0 0 1 0]]

#1st VARIANT

def tile(your_array, your_database, n):
      m=your_database[:]
      for i in range(n):
          newarr=your_array - m[i]
          return newarr
          print newarr

I need to substract an array your_array (is the a1) from an element of an array of the arrays is called your_database (is the group). I try to specify an index of your_database (is the group) , but python says that your_database[:] and m[i] has no attribute getitem()

Then i wrote this code:
2ND VARIANT
Code: Select all
def tile(your_array, your_database, n):
      m=your_database.__getitem__()
      for i in range(n):
          yy=m.__getitem__(i)
          newarr=your_array - yy
          return newarr
          print newarr

But i get an error : 'long' object has no attribute 'getitem'

This function i have written and try to run my code and a mistake occurs at the line #185 . This number of line in my def tile. Thus i haven't called this function, but my code contains it.

1st variant of def tile in tile m=your_database[:] TypeError: 'long' object has no attribute 'getitem'

2nd variant of def tile in tile m=your_database.getitem() AttributeError: 'long' object has no attribute 'getitem'

These function i write to get an substracted array from: a1 - group[i], where i - an element of the big array group .

As i understand right if i specify n - this is numbers of elements of big array (is the group)

Being passed for i'd get my substracted arrays (5*5)

If you have an idea how to substract element of big array *(Element of big array have same size like as array(5*5))* from an array (5*5)
Last edited by Yoriz on Sun Sep 18, 2016 11:13 am, edited 1 time in total.
Reason: First post lock.
SKY_SHY
 
Posts: 1
Joined: Sun Sep 18, 2016 9:56 am

Re: 'long' object has no attribute '__getitem__' Error in a

Postby Yoriz » Sun Sep 18, 2016 11:20 am

The code is passing your_database to the tile function but your_database is not shown in your code anywhere so there is no way of knowing if it should or should not create those errors.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 6 guests