Python Forum
Saving an numpy.ndarray as .ply file in python
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving an numpy.ndarray as .ply file in python
#1
hello,

I open an already existing .ply file and modify it in a loop working with the line in this file.
At the end, I have a numpy.ndarray that I would like to save as a .ply file.
How can I do this ?
numpy.ndarray looks like:
array(['ply\n', 'format ascii 1.0\n', 'element vertex 36\n',
       'property float x\n', 'property float y\n', 'property float z\n',
       'property float score\n', 'property float nx\n',
       'property float ny\n', 'property float nz\n',
       'property float size\n', 'property uchar red\n',
       'property uchar green\n', 'property uchar blue\n', 'end_header\n',
       '13.32 12.84 3.06 -0.352745 -0.230493 0.906887 20 0.74 255 255',
       '13.44 12.84 3.06 0.135449 -0.0514792 0.989446 20 0.25 255 255',
       '13.56 12.84 3.024 0.26937 -0.00564067 0.96302 20 0.34 255 255',
       '13.68 12.84 3 0.023836 0.341656 0.939523 20 0.96 255 255 0 \n',
       '13.8 12.84 3 0.17265 0.491562 0.853557 20 0.93 255 255 0 \n',
       '13.92 12.84 2.94 0.271418 0.421348 0.865331 20 0.55 255 255 0',
       '13.92 13.44 2.412 0.592844 0.469536 0.654272 1 0.28 255 0 0 \n',
       '\n'],
      dtype='|S61')
Reply
#2
https://docs.scipy.org/doc/numpy-1.13.0/....save.html
Reply
#3
(Oct-11-2017, 05:55 PM)Larz60+ Wrote: https://docs.scipy.org/doc/numpy-1.13.0/....save.html

Thank you. But I want to re save it in .ply format.
Reply
#4
Sorry,  this package seems to do that: https://github.com/dranjan/python-plyfile
Reply
#5
(Oct-11-2017, 06:06 PM)Larz60+ Wrote: Sorry,  this package seems to do that: https://github.com/dranjan/python-plyfile

Thanks for the quick reply. I have already read that. It provides a way of reading the file or writing one from scratch. What I want to do is:
1- Read .ply file (as in the link)
2- add an element to the header and to the data as well (for example, before defining the colour I would like to add 'property float score\n' in the header )
3- save the edited version

Can you please help ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Changing the content of the table and saving the new data into another file femke_pythonquestion123 1 1,560 Sep-18-2020, 12:06 PM
Last Post: femke_pythonquestion123
  Spyder: ndarray object of numpy module error python_newbie09 6 17,802 Jul-31-2019, 06:21 AM
Last Post: rohit_w
  Saving to Json file Shambob1874 1 2,456 May-30-2018, 10:00 PM
Last Post: micseydel
  Saving the results from an input in a txt. file pythonenthusiast 2 2,678 Nov-28-2017, 03:52 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020