Python Forum
PyArray_SimpleNew gives "ValueError: array is too big; for 3-cubed array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyArray_SimpleNew gives "ValueError: array is too big; for 3-cubed array
#1
I am using Anaconda Spyder 3.3.6 (Python 3.7) on CentOS 7. I started out with the following code in the surfaceModules module.

static PyObject *  squeezeSurfaces(PyObject* self, PyObject* args)
{
    PyArrayObject *matin, *matout;
    double ***cin, ***cout, dfactor;
    int i,j,k,n,m,l, dims[3], ifactor;

    // Parse tuples separately since args will differ between C fcns
    if (!PyArg_ParseTuple(args, "O!id",
        &PyArray_Type, &matin, &ifactor, &dfactor))  return NULL;
    if (NULL == matin)  return NULL;

    // Check that object input is 'double' type and a matrix
    //   Not needed if python wrapper function checks before call to this routine
    if (not_doublematrix(matin)) return NULL;

    // Get the dimensions of the input
    n=dims[0]=matin->dimensions[0];
    m=dims[1]=matin->dimensions[1];
    l=dims[2]=matin->dimensions[2];

    // Make a new double matrix of same dims
    matout=(PyArrayObject *) PyArray_SimpleNew(3,dims,NPY_DOUBLE);

    Py_INCREF(matin);
    return PyArray_Return(matin);
}
With the following Python code

import surfaceModules as sm
import numpy as NP

x=NP.zeros(27)
for i in range(0,27): x[i]=i 
x=x.reshape(3,3,3)
jfac=2
xfac=1.5
y=sm.squeezeSurfaces(x, jfac, xfac)
I got the following message

__main__:10: DeprecationWarning: PyArray_FromDims: use PyArray_SimpleNew.
__main__:10: DeprecationWarning: PyArray_FromDimsAndDataAndDescr: use PyArray_NewFromDescr.
So I replaced PyArray_FromDims with PyArray_SimpleNew.

This resulted in

ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.
with the same Python code. Note that this happens with both Spyder and Jupyter Notebook.
It is a 3-cubed array so should only have 27 elements altogether.
Reply
#2
Have you tried declaring dims[] as "npy_intp dims[3];"?

casevh
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Elegant way to apply each element of an array to a dataframe? sawtooth500 4 122 22 minutes ago
Last Post: sawtooth500
  Concatenate array for 3D plotting armanditod 1 189 Mar-21-2024, 08:08 PM
Last Post: deanhystad
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,722 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  How Write Part of a Binary Array? Assembler 1 305 Jan-14-2024, 11:35 PM
Last Post: Gribouillis
  Loop over an an array of array Chendipeter 1 525 Nov-28-2023, 06:37 PM
Last Post: deanhystad
  How to remove some elements from an array in python? gohanhango 9 980 Nov-28-2023, 08:35 AM
Last Post: Gribouillis
  IPython errors for numpy array min/max methods muelaner 1 506 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Convert np Array A to networkx G IanAnderson 2 625 Jul-05-2023, 11:42 AM
Last Post: IanAnderson
  Help using a dynamic array excel formula with XLWings FXMonkey 2 1,206 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
  [Newbie] Multiple Array azhuda 3 952 Jun-01-2023, 04:29 AM
Last Post: azhuda

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020