This class inherits from double and overloads the display function to output multidimensional arrays in text format that is compatible for copy and pasting into an interactive Python session.
It doesn't quite work with arbitrary dimensions, since I got stuck with generalised indexing, hence the hackish:
newx = squeeze(x(i,:,:,:,:,:,:,:,:,:,:));
(I'd be interested to hear if theres a different way to do this!)
So at the moment it supports about 12 dimensions, which I thought was probably enough for most copy + paste needs, but if you need more you can just add more colons to the line above - it doesn't seem to do any harm!
Anyway with the file in your Matlab path:
>> x = rand(2,3,4,5);
>> a = array(x)
You can specify a fprintf style format string either in the
constructor or after:
>> a = array(x,'%2.6f')
>> a.format = '%2.2f'
>> x = rand(4,3,2);
Robin (2020). Display Python Formatted Arrays (https://www.mathworks.com/matlabcentral/fileexchange/24087-display-python-formatted-arrays), MATLAB Central File Exchange. Retrieved .
another silly bug - missing off first element...
Update file - fix problem with column array
More detailed description with an example.