Skip to content

Unexpected formatting for 3D arrays #40

@RicSherlock

Description

@RicSherlock

This is a huge improvement on the display of matrices and arrays in Python!!! Thank you!!

My experience with working with 2D (& 4D) arrays has been fantastic, however I was quite confused when trying to display a stack of matrices (i.e. a 3D array), or any array with an odd rather than even number of dimensions.

I was expecting to see something similar to print(array3d), but both mdisplay shows something that appears quite different`.

import numpy as np
np.random.seed(55)
array = np.random.random((2,3,4))
print(array)
mdisplay(array)

I was expecting the last 2 dimensions to describe the rows and columns of the sub-matrices respectively. This matches mdisplay's current behaviour when there is an even number of dimensions, but not when the number of dimensions is odd. In that case it seems that, in effect, an extra dimension is inserted into the display so (2,3,4) is displayed as (2,3,1,4). In the same way a 5D array with dimensions (2,3,4,5,6) is effectively displayed as (2,3,4,5,1,6).

mdisplay(array.reshape(2,3,1,4)  # no change to current behaviour
mdisplay(array.reshape(2,1,3,4)  # suggested new behaviour

My preference for arrays with an odd number of dimensions, would be to insert the "dummy" extra dimension of value 1 as the 3rd-to-last dimension, i.e. (2,3,4) -> (2,1,3,4) and (2,3,4,5,6) -> (2,3,4,1,5,6). That way the rows & columns in the last 2 dimensions would always display as a "matrix".

I'm interested in whether this suggestion makes sense to you, or whether there are other reasons for the current behaviour?

Thanks again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions