← Back to team overview

dolfin team mailing list archive

Vector to numpy array and vice verse

 

Hello!

You can easy get the the values of a dolfin vector in python, by calling 
Vector.array(). A numpy array is returned. But you can't do the other way 
around, i.e, initialize a dolfin Vector in python with a numpy array. 
Or you can but its done in two stages:

  na = ones(10,'d')
  dv = Vector(len(na))
  dv.set(na)

It would be straight forward to extend the Vector interface, together with all 
the different variants of Vectors, so one can do

  na = ones(10,'d')
  dv = Vector(na)

I think this is a convinient way of initializing a Vector in dolfin, do we 
want this?

With this extension of the Vector interface we can extend the Function 
constructor in python to also take a numpy array with values, instead of only 
a Vector (this is what I really want).

What do you say? Any considerations conserning the upcomming revamp of 
Function and LA interface concerning parallelity?

Johan


Follow ups