numpy - 2D matrix/array - initialization like in Matlab...
Emile van Sebille
emile at fenx.com
Mon Oct 15 17:52:26 EDT 2012
someone wrote:
> How to initialize my array directly using variables ?
>
> It could also be that I wanted:
>
> test11 = 1
> test12 = 1.5
> test13 = 2
> test21 = 0
> test22 = 5
>
> Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')
>
> Etc... for many variables...
>
> Appreciate ANY help, thank you very much!
You could use string interpolation:
Dx = numpy.matrix('%s %s %s; %s %s -0.5; 0 -0.5 1.5'
% (test11 test12 test13 test21 test22))
Emile
More information about the Python-list
mailing list