built-in function to convert a numpy ndarray to escript data object

Asked by ceguo

Hi,

To create an escript data object such as Tensor4() from a numpy ndarray, I usually do(say t = numpy.ones((npts,2,2,2,2))):

tangent = Tensor4(0.0, Function(domain))
for i in range(npts):
    tangent.setValueOfDataPoint(i, t[i])

Is there a built-in function for direct conversion from the numpy ndarray to the escript data, like in the opposite operation, one can use toListOfTuples()? If no, would it possible to have one implemented, as I think it's very useful when escript is coupled with other codes when data type conversion is frequently required.

Best,
Ning

Question information

Language:
English Edit question
Status:
Solved
For:
esys-escript Edit question
Assignee:
No assignee Edit question
Solved by:
ceguo
Solved:
Last query:
Last reply:
Revision history for this message
Adam Ellery (aellery) said :
#1

Hi Ning,

At present there is no function that converts numpy arrays into Data objects, but we plan to introduce such a function in a future version, (probably version 5.6 or 5.7).

Best regards,

Adam

Revision history for this message
ceguo (hhh-guo) said :
#2

Hi Adam,

Good to know that. Thanks.

Best,
Ning