I am trying to predict the depths from a single. the prediction is in .mat structure
{'__header__': b'MATLAB 5.0 MAT-file Platform: nt, Created on: Mon Jun 24 20:53:06 2019', '__version__': '1.0', '__globals__': [], 'mat': array
([[[[45.593273 ],
[44.393333 ],
[45.71833 ],
...,
[20.923761 ],
[22.743704 ],
[25.33584 ]],
[[44.40423 ],
[43.71836 ],
[45.744335 ],
...,
[17.319963 ],
[18.493673 ],
[19.687391 ]],
[[45.414154 ],
[45.360767 ],
[46.82794 ],
...,
[17.41372 ],
[18.701914 ],
[19.105356 ]],
...,
[[ 6.8809724],
[ 6.5185905],
[ 6.602861 ],
...,
[ 6.6090174],
[ 6.587162 ],
[ 7.3165007]],
[[ 7.0013733],
[ 6.384803 ],
[ 6.6147423],
...,
[ 6.46376 ],
[ 6.434711 ],
[ 7.4840846]],
[[ 7.9435554],
[ 6.6214004],
[ 6.654035 ],
...,
[ 7.4519753],
[ 7.712751 ],
[ 9.646708 ]]]], dtype=float32)}
The final element mat is of the array type. I want to take the mat array and plot using matplotlib.
When I get the type and shape of the above I get this
The type of array is <class 'numpy.ndarray'>.
The shape of the array is (1, 96, 320, 1).
I am not able to understand what does this means (1, 96, 320, 1) never seen such kind of shape with 4 parameters.
import scipy.io as sio
import numpy as np
import matplotlib.pyplot as plt
mat_content = sio.loadmat('2011_09_26_drive_0002_sync_image_0000000023_image_02.mat')
#print(mat_content)
print(mat_content.keys())
array_content = mat_content['mat']
print(array_content)
print('The type of array is ',type(array_content))
print('The shape of array is ', array_content.shape)
#plt.plot(array_content)
#plt.show()
when I run the above code I get this error
Traceback (most recent call last):
File "2.py", line 11, in <module>
plt.plot(array_content)
File "C:\Users\snanr\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2811, in plot
is not None else {}), **kwargs)
File "C:\Users\snanr\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "C:\Users\snanr\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1611, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Users\snanr\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 393, in _grab_next_args
yield from self._plot_args(this, kwargs)
File "C:\Users\snanr\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 370, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Users\snanr\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 234, in _xy_from_xy
"shapes {} and {}".format(x.shape, y.shape))
ValueError: x and y can be no greater than 2-D, but have shapes (1,) and (1, 96, 320, 1)
I expect the output to be able to use the array and plot the array as an image using matplotlib.
arr = array_content[0,:,:,0]orarr = np.squeeze(array_content)should remove the extra size 1 dimensions.plt.plotexpects a 2-D array to plot for a line plot. Your array is 4-D. Usually if you want to plot an image you useplt.imshow. I'm still not sure if it will be able to plot a 4-D array though