Forum: Poser Python Scripting


Subject: Moving morphs between different figures

Cage opened this issue on Dec 20, 2006 · 1232 posts


adp001 posted Thu, 13 March 2008 at 7:48 PM

Quote - I'll take a look at struct, thanks.  In our current code, we're using lists-of-lists-of-floats to represent multiple vertices.  For example, 2 vertices would be represented as:

2verts = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]

Use Numeric (or NumPy) and this problem is solved with .flat, =resize(,new_shape), and/or a few more in no time (see Numeric Manual: http://numpy.scipy.org//numpydoc/numpy.html).

flat Accessing the flat attribute of an array returns the flattened, or ravel() 'ed version of that array, without having to do a function call. The returner array has the same number of elements as the input array, but is of rank-1. One cannot set the flat attribute of an array, but one can use the indexing and slicing notations to modify the contents of the array:

>>> print a

[[0 1 2]

[3 4 5]

[6 7 8]]

>>> print a.flat

[0 1 2 3 4 5 6 7 8]

>>> a.flat = arange(9,18)

Traceback (innermost last):

File "", line 1, in ?

AttributeError: Attribute does not exist or cannot be set

>>> a.flat[4] = 100

>>> print a

[[ 0 1 2]

[ 3 100 5]

[ 6 7 8]]

>>> a.flat[:] = arange(9, 18)

>>> print a

[[ 9 10 11]

[12 13 14]

[15 16 17]]