0

I am using the "Delaunay triangulation" module in from "scipy.spatial." I am able to generate an array (actually an ndarray, since I am using x, y and z coordinates) from the "simplices," but unable to export it into any format I can use for further processing.

The code is straightforward:

tri = Delaunay(points)
a = np.array(points[tri.simplices])

What I get looks like this:

   [[7.02192702e+05, 7.53337067e+06, 1.43116411e+02],
    [7.02275075e+05, 7.53339801e+06, 1.53508313e+02],
    [7.02073353e+05, 7.53340902e+06, 1.40979450e+02],
    [7.02288667e+05, 7.53338498e+06, 1.52185457e+02]],

   ...,

   [[7.02038856e+05, 7.53333613e+06, 1.39584833e+02],
    [7.02069568e+05, 7.53327029e+06, 1.46902739e+02],
    [7.02062213e+05, 7.53331215e+06, 1.31241316e+02],
    [7.02040635e+05, 7.53329922e+06, 1.30787203e+02]],...

By playing around with it I can export it into an extended string:

702299.971067+7533414.077516+163.2373+...

But I would prefer to have it in a .csv file with columns, or convert that extended string into a table or array with a set number of columns.

I assume I'm doing something wrong in saving or writing the output, but can't find any obvious solutions to saving/exporting arrays online anywhere.

Any ideas? suggestions?

1 Answer 1

0

Once it's in an np.ndarray format, just use np.savetxt() to save the array to a .txt file. (see: https://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html).

This is the simplest method I know of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.