I was wondering if it was possible to create a nested matrix in python. Here I define my matrix A
A = array([[ 12., 0.],[ 0., 4.]])
I would like to replace the zeros with a generic 2×2 matrix and then plot everything with imshow(). Is that possible?
I tried defining my nested matrix this way
A = array([[ 12., array([[ 1., 1.],[ 1., 1.]])],[ 0., 4.]])
but I got this error message
ValueError: setting an array element with a sequence.
Now you can insert sequences, without getting the ValueError
The other part of the OP–passing an Array like this to Matplotlib’s imshow, is a problem.
imshow visually represents a 2D array as a cloud of points positioned on the canvas according to their x, y indices. The value at that index is indicated according to different colors and color intensities based on a colormap which maps color to array value. Therefore, valid arguments for imshow’s data parameter are:
NumPy arrays of higher dimension in two (and only these two AFAIK) which imshow can interpret as
NumPy 2D array of rgb tuples (x, y, r, b, g)
NumPy 6D arrays, which are interpreted as a 2D array of rgba
tuples (x, y, r, g, b, a)