any algorithm or function in python to convert hollow stl("file format") object into filled(solid) stl object(file formate) - python

is any function or algorithm to convert hollow.stl object into filled.stl object using python
I want to convert any hollow obj.stl to fill (solid) obj.stl using python

Related

Replace quotes in a python array or arrays

I have a dict object in python:
'polygon': {'coordinates': [[['51.89600366973369,5.604579537426986'], ['51.88589816283178,5.598937488274174'], ['51.882074887477046,5.620585782912315'], ['51.891197214447004,5.622057621577596']]]}
I want to replace the ' from the coordinates with nothing so:
'51.89600366973369,5.604579537426986' becomes 51.89600366973369,5.604579537426986
How can I achieve that in python? To be honest, I don't now where to start.
Yes now it's indeed an array with a string with geographic coordinates, but elasticsearch want the according the geojson format (https://www.rfc-editor.org/rfc/rfc7946) which is not a string. The python function needs tranform the data and then stream it to elasticsearch.

Convert Points Datatype of vtkUnstructuredGrid

I have an unstructured grid where the points are given as doubles. I'd like to convert them to floats.
What's the easiest way to do this?
So far I've been resorting to the hacky method of writing the grid to a legacy vtk ascii file and simply exchanging double for float in the header...
You could just recreate a dataset manually, or use a vtkArrayCalculator Filter for this task, with the following parameters :
Coordinate Results : ON
Function : "coords"
Result Array Type : Float
If you used ParaView, it would look like this :

networkx calculating numeric assortativity requires int?

I am trying to use networkx to calculate numeric assortativity based on a numeric attribute that I set to nodes. My node attributes are floats. When I call the assortativity function:
assort = nx.numeric_assortativity_coefficient(G,'float_attr')
I got the following errors.
File "/some dir.../networkx/algorithms/assortativity/correlation.py", line 229, in numeric_assortativity_coefficient
a = numeric_mixing_matrix(G,attribute,nodes)
File "/some dir.../networkx/algorithms/assortativity/mixing.py", line 193, in numeric_mixing_matrix
mapping=dict(zip(range(m+1),range(m+1)))
TypeError: range() integer end argument expected, got float.
I checked the documentation page of networkx assortativity algorithm and it did not say the numeric attributes have to be int. Anyone knows if that's required?
BTW, I used the same network and a gender attribute (set to 0 and 1) to calculate both the attribute and the numeric assortativity. I had no problem with that. So it seems that the problem is with the int/float type of the node attribute.
problem solved by converting the float variable into int using the following method
int(round(float_attr*1000, 0))
submitted an issue here and got a confirmatory answer that it only deals with discrete int values.
Peformance-wise, since my network is not huge (200+ nodes), it still takes <1 min to do the calculation.

Convert string representation of list of objects back to list in python

I have a list of objects, that has been stringified:
u'[<object: objstuff1, objstuff2>, <object: objstuff1, objstuff2>]'
I want to convert this back into a list:
[<object: objstuff1, objstuff2>, <object: objstuff1, objstuff2>]
I've tried using ast.literal_eval(), but unfortunately, it doesn't seem to work if the elements are objects, and I get a SyntaxError.
Is there any way I can reconvert my string representation of the list of objects back into a list?
You need to have a look at the pickle module to do this.
Basically, dump your objects using pickle.dumps, and load them back using pickle.loads.
ast.literal_eval doesn't work obviously, because there is a lot of information related to the objects (like attributes, and values) which is simply not captured in that string. Also note that you will be able to resurrect only the pickled data, if all you have are those string representations right now, you won't be able to create the objects back from them because of the information loss.

Import matrix from text file using python

I have two text files that have matrices written in them(not numpy matrices, so its a list of lists). These matrices are written in string format, so the text file looks like this :
[[1,2,3],[3,4,5],[6,7,8]],[[3,3,3],[5,6,7],.....
I want to read this matrix back from the text file using python. I can't read using numpy as it gives ValueError: could not convert string to float
Is there anyway to do this? Would it be easier if I just wrote the matrix as a numpy matrix in the first place(I need to change code of a previous program for that, and was just wondering if there was a python way of loading matrices when it was stored as a string in a text file)?
You could make use of the ast module:
import ast
strArray = "[[1,2,3],[3,4,5],[6,7,8]]"
# evaluates the array in string format and converts it to a python array object
array = ast.literal_eval(strArray)
note:
For multiple nested arrays like you have, literal_eval will most likely convert the string into a tuple with nested arrays as elements. Just keep that in mind as you use this module.

Categories