[NUMPY] "ValueError: total size of new array must be unchanged" juston Windows

P

Paolo Zaffino

Hello,
I wrote a function that works on a numpy matrix and it works fine on
Mac OS and GNU/Linux (I didn't test it on python 3)
Now I have a problem with numpy: the same python file doesn't work on
Windows (Windows xp, python 2.7 and numpy 2.6.1).
I get this error:

matrix=matrix.reshape(a, b, c)
ValueError: total size of new array must be unchanged

Why? Do anyone have an idea about this?
Thank you very much.
 
S

Steven D'Aprano

Paolo said:
Hello,
I wrote a function that works on a numpy matrix and it works fine on
Mac OS and GNU/Linux (I didn't test it on python 3)
Now I have a problem with numpy: the same python file doesn't work on
Windows (Windows xp, python 2.7 and numpy 2.6.1).
I get this error:

matrix=matrix.reshape(a, b, c)
ValueError: total size of new array must be unchanged

Why? Do anyone have an idea about this?
Thank you very much.

Please give sample values for matrix, a, b and c that demonstrate the issue.

What version of Python and numpy are you using on Mac and Linux?
 
N

Nobody

I wrote a function that works on a numpy matrix and it works fine on
Mac OS and GNU/Linux (I didn't test it on python 3)
Now I have a problem with numpy: the same python file doesn't work on
Windows (Windows xp, python 2.7 and numpy 2.6.1).
I get this error:

matrix=matrix.reshape(a, b, c)
ValueError: total size of new array must be unchanged

Why?

What it says. The reshape()d array must have the same total number of
elements as the original array.

If it works on one platform and not on another, that indicates that either
"matrix" has a different shape on different platforms, or a*b*c is
different on different platforms.

As no-one here (except you) has any idea how matrix, a, b and c are
getting their values, it's impossible for us to say why they're getting
different values on different platforms.
 
P

Peter Otten

Paolo said:
Nobody can help me?

Add the lines

print "a=%r, b=%r, c=%r" % (a, b, c)
print "type=%s, shape=%r, size=%r" % (type(matrix), matrix.shape,
matrix.size)

before this one

and tell us what it prints both on a system where it works and where it
doesn't.

If a, b, and c are all integers and

a * b * c == matrix.size

try passing a tuple:

matrix = matrix.reshape((a, b, c)) # note the double parens
 
M

MRAB

Nobody can help me?
Others have already tried to help you.

What is the shape and size of 'matrix' before, and what are the values
of 'a', 'b' and 'c'?

Print them in the ones which work (GNU/Linux and Mac OS) and the one
which doesn't (Windows). Do they print the same values?

Do not assume that they are the same. Print them to make sure.
 
P

Prasad, Ramit

From: [email protected] [mailto:p[email protected]] On Behalf Of Paolo Zaffino
Sent: Friday, October 14, 2011 3:55 PM
To: (e-mail address removed)
Subject: Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

Nobody can help me?


2011/10/12 Paolo Zaffino <[email protected]>
I wrote a function thaht works on a 3D matrix.
As first thing I have an array and I want reshape it into a 3D matrix (for further manipulations).
For this reason I wrote in a row:

matrix=matrix.reshape(a, b, c).T

It work fine on GNU/Linux and Mac OS butnot on Windows.
In Windows I get this error:

matrix=matrix.reshape(a, b, c).T

ValueError: total size of new array must be unchanged
Thank you.



2011/10/11 DavidRobinow said:
Nobody can help me?
 Nope, not unless you post some code. Your problem description is too vague.
==============================================================================

You can do this by converting to an array.

mat = numpy.matrix( [[1,2,],[3,4],[5,6],[7,8]] )
numpy.array( mat )
array([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
array([[[1, 2],
[3, 4]],

[[5, 6],
[7, 8]]])


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
P

Prasad, Ramit

Redirecting to his question to the list.
I need of a matrix, not ofan array.
But is this error due to a numpy bug?

I am not an expert on NumPy/SciPy, but I do not believe matrixes are allowed to be3 dimensional. Google only produced results of 3 dimensional arrays.


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top