Q:

How to change a structured array item size in Numpy?

I am trying to change the size of an item in a Numpy structured array. The following code triggered an error saying the array can not be broadcasted because of the size difference. Is there a way to accomplish my goal short of making a new structured array?
import numpy as np

x = np.zeros(1, dtype=['value','f4',(2,3)])
x['value'][0] = np.random.rand(4,2)

A:

You can't change the size or shape of fields in a structured array.  There may be a few values of the dtype that you can change (maybe names?).  But things that control the layout of the data, e.g. number of bytes per element, cannot be changed in place.  You need to create a new array, and transfer data (if possible).
Initially you are allocating a (2,3) array of floats to each element of x.  So the size of each is 6*4 ('f4') bytes.  Then you want to write a (4,2) array to the same slot, 8*4 bytes.  It can't fit.
The whole point to using numpy arrays is to define fixed sized objects, ones can be traversed in a multidimensional way quickly.
You could define:
x=np.zeros(1, dtype=[('value', object)])

Now you can write a (2,3) array to x['value'][0], and then write a (4,2) array to.  x data just contains pointers to arrays, or other objects, that exist elsewhere in memory.
Better yet, use Python lists.

Looking at your original x with more elements might help
x=np.zeros(3, dtype=[('value', 'f4', (2,3))])

The (2,3) pattern is repeated:
array([([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],),
       ([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],),
       ([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],)], 
      dtype=[('value', '<f4', (2, 3))])

and if you look at just the field, you get a 3d array, 3 'rows' of (2,3) arrays is a (3,2,3) array
x['value'].shape
# (3, 2, 3)

