By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

having problem in making matrix in python

P: 1
I want to make a matrix with 5 rows and 4 columns. The problem is when I run it there appears an error that "Traceback (most recent call last): File "C:\Users\yasini\Desktop\", line 21, in ['ART|Ф',0.71], ['N|Ф',0.29], ['V|Ф',0.0001], ['P|Ф',0]]).reshape(5,4) ValueError: total size of new array must be unchanged".

How can I solve it?

import numpy as np
A = np.array([['ART|ART',0], ['N|ART',1], ['V|ART',0], ['P|ART',0],
['ART|N',0.0001], ['N|N',0.13], ['V|N',0.43], ['P|N',0.44],
['ART|V',0.65], ['N|V',0.35], ['V|V',0.0001], ['P|V',0.0001],
['ART|P',0.74], ['N|P',0.26], ['V|P',0.0001], ['P|P',0.0001],
['ART|Ф',0.71], ['N|Ф',0.29], ['V|Ф',0.0001], ['P|Ф',0]]).reshape(5,4)
print (A)

When I omit the zero from the last cell (['P|Ф',0]), it works right and a 5*4 matrix is produced but when I add zero again this error occurs.
Jun 22 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.