bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / io / matlab / _miobase / matdims
function
scipy.io.matlab._miobase:matdims
source: build-install/usr/lib/python3.14/site-packages/scipy/io/matlab/_miobase.py:259
Signature
def matdims(arr, oned_as = column)Summary
Determine equivalent MATLAB dimensions for given array
Parameters
arr: ndarrayInput array
oned_as: {'column', 'row'}, optionalWhether 1-D arrays are returned as MATLAB row or column matrices. Default is 'column'.
Returns
dims: tupleShape tuple, in the form MATLAB expects it.
Notes
We had to decide what shape a 1 dimensional array would be by default. np.atleast_2d thinks it is a row vector. The default for a vector in MATLAB (e.g., >> 1:12) is a row vector.
Versions of scipy up to and including 0.11 resulted (accidentally) in 1-D arrays being read as column vectors. For the moment, we maintain the same tradition here.
Examples
import numpy as np from scipy.io.matlab._miobase import matdims matdims(np.array(1)) # NumPy scalar matdims(np.array([1])) # 1-D array, 1 element matdims(np.array([1,2])) # 1-D array, 2 elements matdims(np.array([[2],[3]])) # 2-D array, column vector matdims(np.array([[2,3]])) # 2-D array, row vector matdims(np.array([[[2,3]]])) # 3-D array, rowish vector matdims(np.array([])) # empty 1-D array✓
(0, 0)
matdims(np.array([[]])) # empty 2-D array matdims(np.array([[[]]])) # empty 3-D array✗
(1, 1, 0)Optional argument flips 1-D shape behavior.
matdims(np.array([1,2]), 'row') # 1-D array, 2 elements
✓(1, 2)The argument has to make sense though
matdims(np.array([1,2]), 'bizarre')
✓Traceback (most recent call last):
File "<doctest scipy.io.matlab._miobase:matdims[0]>", line 1, in <module>
matdims(np.array([1,2]), 'bizarre')
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/dev/scipy/build-install/usr/lib/python3.14/site-packages/scipy/io/matlab/_miobase.py", line 333, in matdims
raise ValueError(f'1-D option "{oned_as}" is strange')
ValueError: 1-D option "bizarre" is strange
Aliases
scipy.io.matlab._mio4.matdims