Apress / python-for-matlab-development

Source Code for 'Python for MATLAB Development' by Albert Danial
Other
39 stars 20 forks source link

py2mat: bool not recognized #3

Closed harry-commin-enclustra closed 1 year ago

harry-commin-enclustra commented 1 year ago

Currently, py2mat does not support py.numpy.ndarray with dtype.name == "bool".

For example:

>> py2mat(py.numpy.array([false, true]))
py2mat: bool not recognized

It seems that this could be fixed by adding a case for bool:

    case 'py.numpy.ndarray'
      switch string(x_py.dtype.name)
        case "bool"
          x_mat = logical(x_py);

It then appears to work as expected:

>> py2mat(py.numpy.array([false, true]))

ans =

  1×2 logical array

   0   1