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

Discussion in 'Python' started by Paolo Zaffino, Oct 9, 2011.

  1. 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.
    Paolo Zaffino, Oct 9, 2011
    #1
    1. Advertising

  2. Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

    Paolo Zaffino wrote:

    > 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?



    --
    Steven
    Steven D'Aprano, Oct 10, 2011
    #2
    1. Advertising

  3. Paolo Zaffino

    Nobody Guest

    Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

    On Sun, 09 Oct 2011 13:59:11 -0700, Paolo Zaffino wrote:

    > 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.
    Nobody, Oct 10, 2011
    #3
  4. Re: [NUMPY] "ValueError: total size of new array must be unchanged"just on Windows

    2011/10/11 Paolo Zaffino <>:
    > Nobody can help me?

    Nope, not unless you post some code. Your problem description is too vague.
    David Robinow, Oct 11, 2011
    #4
  5. Paolo Zaffino

    Peter Otten Guest

    Re: [NUMPY] "ValueError: total size of new array must be unchanged"just on Windows

    Paolo Zaffino wrote:

    > 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

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


    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
    Peter Otten, Oct 11, 2011
    #5
  6. Paolo Zaffino

    MRAB Guest

    Re: [NUMPY] "ValueError: total size of new array must be unchanged"just on Windows

    On 14/10/2011 21:55, Paolo Zaffino wrote:
    > 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.
    >
    > 2011/10/12 Paolo Zaffino < <mailto:>>
    >
    > 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 but not 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 David Robinow <
    > <mailto:>>
    >
    > 2011/10/11 Paolo Zaffino <
    > <mailto:>>:
    > > Nobody can help me?

    > Nope, not unless you post some code. Your problem description
    > is too vague.
    >
    MRAB, Oct 14, 2011
    #6
  7. RE: [NUMPY] "ValueError: total size of new array must be unchanged"just on Windows

    From: python-list-bounces+ramit.prasad= [mailto:python-list-bounces+ramit.prasad=] On Behalf Of Paolo Zaffino
    Sent: Friday, October 14, 2011 3:55 PM
    To:
    Subject: Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

    Nobody can help me?


    2011/10/12 Paolo Zaffino <>
    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 <>
    2011/10/11 Paolo Zaffino <>:

    > 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]])

    >>> a = _
    >>> numpy.reshape( a, (2,2,2))

    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.
    Prasad, Ramit, Oct 14, 2011
    #7
  8. RE: [NUMPY] "ValueError: total size of new array must be unchanged"just on Windows

    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.
    Prasad, Ramit, Oct 19, 2011
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. drife
    Replies:
    1
    Views:
    352
    Travis E. Oliphant
    Mar 1, 2006
  2. Duncan Smith
    Replies:
    3
    Views:
    409
    Duncan Smith
    Apr 25, 2007
  3. Replies:
    2
    Views:
    479
    Robert Kern
    Nov 13, 2007
  4. W. eWatson
    Replies:
    2
    Views:
    913
    W. eWatson
    Nov 23, 2009
  5. Tom Kacvinsky

    Installing numpy over an older numpy

    Tom Kacvinsky, Jun 15, 2012, in forum: Python
    Replies:
    1
    Views:
    334
    Miki Tebeka
    Jun 15, 2012
Loading...

Share This Page