0

I have Dataframe of "IMDB data from 2006 to 2016" which is in Kaggle site: https://www.kaggle.com/PromptCloudHQ/imdb-data . I have made it as numpy array but when I want to assign the inner product of two row of it to numpy.float64 variable, it gives me this error:

sim[i][1] = np.inner(vec[i],vec[1])
TypeError: 'numpy.float64' object does not support item assignment

here is my code:

X = trainset.drop(['Description', 'Runtime','Director','Title', 'ID'], axis=1)
X.Revenue = X.Revenue.fillna(X.Revenue.mean())
X.Metascore= X.Metascore.fillna(X.Revenue.min())
features = ['Genre','Actors']
for f in features:
    X_dummy = X[f].str.get_dummies(',').add_prefix(f + '.')
    X = X.drop([f], axis = 1)
    X = pd.concat((X, X_dummy), axis = 1)
vec = np.ones((1000,2422), dtype=np.uint8)
vec = X.values
sim = np.ones((1000,1), dtype=np.float64)
for i in range (1,1000):
    sim[i][1] = np.inner(vec[i],vec[1])

and when I get the type of this inner product it gives me exactly this type:

>>chi = np.inner(vec[0],vec[0])
>>print(type(chi))
<class 'numpy.float64'>
5
  • Ca you add some smple data for minimal, complete, and verifiable example ? Commented Jul 26, 2018 at 7:27
  • 1
    vec = np.array((1000,2422), dtype=np.uint8), sim = np.array((1000,1), dtype=np.float64) are these tuples supposed to be the shapes of the arrays? If so, you are using them wrong. Use the shape argument in a populated array like np.ones or np.zeros. Commented Jul 26, 2018 at 7:29
  • @jezrael HI jezrael! yes but I'm new and I had a little problem with link or photo uploading but I use the data of this link: (kaggle.com/PromptCloudHQ/imdb-data) Commented Jul 26, 2018 at 8:48
  • @user2285236 yes I tried with these form too but I get this same error. Commented Jul 26, 2018 at 8:51
  • @user2285236 the problem was the complex variable which I miss them but with the np.array it did not solved and I used np.ones as you told, do you know why this happened? Commented Jul 26, 2018 at 14:18

1 Answer 1

1

I find how this problem happened, I have assigned float variable to my array but when I used fillna with mean function and after that in inner product it returns some complex variable so I changed the array type to this form:

sim = np.ones((1000,1), dtype=np.complex_)

and the problem was solved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.