# Converting Octave vector to Sage list

I have a Sage notebook that combines Sage and Octave code. How can I make the output of the Octave code (a vector) available to Sage as a list or vector?

Converting Octave vector to Sage list

1

So one can do that at least:

```
sage: octave = Octave()
sage: w = octave([1, 2, 3])
sage: Matrix(ZZ, w)
[1 2 3]
sage: w = octave([pi, 5.7, 3])
sage: Matrix(RR, w)
[3.14159000000000 5.70000000000000 3.00000000000000]
```

1

For completeness:

In general, you should be able to access variables from other programs using the methods in this question. Unfortunately, as vdelecroix points out, Sage's reverse interface to Octave is too rudimentary.

```
sage: O = octave([1,2,3])
sage: O._sage_()
Traceback (click to the left of this block for traceback)
...
NotImplementedError: Unable to parse output: 1 2 3
```

But maybe someone will write a better parser for various Octave objects... and this *will* work for very simple things like integers.

1

Hi,

I did not find anything in the documentation. But you can at least parse the ouptut of octave as a string:

```
sage: v = octave('[1,5,7]')
sage: str(v)
'\n\n 1 5 7\n\n'
sage: vector(map(Integer,str(v).split()))
(1, 5, 7)
```

The function `map`

juste evaluate the function `Integer`

on each element of `str(v).split()`

which is the list ['1','5','7']. The method `split`

of strings is very useful: it splits a string at each space character.

Asked: **
2013-05-27 15:32:02 -0600
**

Seen: **507 times**

Last updated: **Sep 24 '15**

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.

Does [the Sage-Octave interface page](http://www.sagemath.org/doc/reference/interfaces/sage/interfaces/octave.html) help?

No, it doesn't. It describes a function for going from a Sage list to an Octave matrix, but I need to go the other way.

For square matrices, there is the following bad behaviour:

Yikes! Please open a ticket. Probably that isn't supported, but then it should be checked...

But this works