[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Integrating Pytave and Nnet
From: |
Mike Miller |
Subject: |
Re: Integrating Pytave and Nnet |
Date: |
Wed, 19 Apr 2017 12:35:29 -0700 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Wed, Apr 19, 2017 at 11:31:53 -0700, enricobertino wrote:
> Regarding pytave, I had some problems with the conversion of the pyobects.
> In particular I noticed that there is not a conversion of float32 and
> strings from python to octave. Is this correct or am I doing something
> wrong?
This is correct. There's not a lot of documentation yet on implicit vs
explicit conversions, but the intent is to mimic Matlab's conventions.
The following Python types are converted to Octave types implicitly
bool -> logical
int -> int64 (Python 2 only)
float -> double
complex -> complex double
All others remain as Python types and must be explicitly converted.
To explicitly convert a py.str to Octave string, use char(s). To
explicitly convert a py.numpy.float32 to Octave numeric value, use
double(x) or single(x).
The reason a numpy float64 converts automatically is because it is
derived from Python's builtin float type.
I have a couple additional notes on your scripts, if you don't mind.
You don't need to import modules, just call the fully qualified names
and the interface takes care of importing the module automatically.
For example, just use "py.sys.path.insert(int32(0), "/some/dir")"
instead of "sys = py.__import__(...".
The same goes for any user-defined modules, "py.mnist_class.MNIST()"
works just fine.
Try to avoid using pycall or pyeval directly, since they are not Matlab
compatible functions. You should be able to call Python functions and
classes directly with just the "py." prefix.
For example, just use "py.dict(pyargs(..." instead of using pycall.
You can also use the "list of pairs" dict constructor, purely a matter
of choice. These both construct the same dict:
py.dict (pyargs ("images", images, "labels", labels))
py.dict ({{"images", images}, {"labels", labels}})
--
mike
- Re: Integrating Pytave and Nnet, enricobertino, 2017/04/03
- Re: Integrating Pytave and Nnet, Mike Miller, 2017/04/03
- Re: Integrating Pytave and Nnet, enricobertino, 2017/04/06
- Re: Integrating Pytave and Nnet, enricobertino, 2017/04/16
- Re: Integrating Pytave and Nnet, Francesco Faccio, 2017/04/26
- Re: Integrating Pytave and Nnet, Mike Miller, 2017/04/27
- Re: Integrating Pytave and Nnet, Mike Miller, 2017/04/28