<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hey Randy,<div><br></div><div>I'm not an expert on this, but the issue is with whether the numpy array is in "C" or "Fortran" order in memory -- numpy_to_vtk() expects "C" ordering. You can see whether the array is "C_CONTIGUOUS" or "F_CONTIGUOUS" by typing array_name.flags</div><div><br></div><div>There might be a better way, but you can get around this by making a copy that has the right order, either by invoking .copy() which uses the "C" default, or by explicitly copying with the correct order flag.</div><div><br></div><div>-Eric</div><div><br></div><div># =================================</div><div><div>In [1]: import numpy as N</div><div><br></div><div>In [2]: from vtk.util import numpy_support as VN</div><div><br></div><div>In [3]: xx = N.array([[1,2],[3,4]])</div><div><br></div><div>In [4]: xx.flags</div><div>Out[4]: </div><div>  C_CONTIGUOUS : True</div><div>  F_CONTIGUOUS : False</div><div>  OWNDATA : True</div><div>  WRITEABLE : True</div><div>  ALIGNED : True</div><div>  UPDATEIFCOPY : False</div><div><br></div><div>In [5]: VN.numpy_to_vtk(xx)</div><div>Out[5]: (vtkLongArray)0x10bea32a0</div><div><br></div><div>In [6]: xx = N.array([[1,2],[3,4]], order='F')</div><div><br></div><div>In [7]: xx</div><div>Out[7]: </div><div>array([[1, 2],</div><div>       [3, 4]])</div><div><br></div><div>In [8]: VN.numpy_to_vtk(xx)</div><div>---------------------------------------------------------------------------</div><div>AssertionError                            Traceback (most recent call last)</div><div><br></div><div>/Users/emonson/Programming/Python/VTK/Charts/<ipython console> in <module>()</div><div><br></div><div>/Users/emonson/Programming/VTK_git/VTK/build/Wrapping/Python/vtk/util/numpy_support.pyc in numpy_to_vtk(num_array, deep, array_type)</div><div>    130 </div><div>    131     shape = z.shape</div><div>--> 132     assert z.flags.contiguous, 'Only contiguous arrays are supported.'</div><div>    133     assert len(shape) < 3, \</div><div>    134            "Only arrays of dimensionality 2 or lower are allowed!"</div><div><br></div><div>AssertionError: Only contiguous arrays are supported.</div><div><br></div><div>In [9]: xx.flags</div><div>Out[9]: </div><div>  C_CONTIGUOUS : False</div><div>  F_CONTIGUOUS : True</div><div>  OWNDATA : True</div><div>  WRITEABLE : True</div><div>  ALIGNED : True</div><div>  UPDATEIFCOPY : False</div><div><br></div><div>In [10]: yy = N.array(xx, order='C')</div><div><br></div><div>In [11]: VN.numpy_to_vtk(yy)</div><div>Out[11]: (vtkLongArray)0x10c017270</div><div><br></div><div>In [12]: zz = xx.copy()</div><div><br></div><div>In [13]: VN.numpy_to_vtk(yy)</div><div>Out[13]: (vtkLongArray)0x10c0178d0</div></div><div><br></div><div><br></div><div><br></div><div><div><div>On Nov 8, 2010, at 2:27 PM, Randy Heiland wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class="">Can someone shed light on the following error?<div class=""><br class=""></div><div class=""><div class="">>>> teMtx</div><div class="">array([[  0.00000000e+00,   2.21433476e-07,   1.29724158e-06, ...,</div><div class="">          1.13706443e-06,   1.22732023e-06,   1.80498142e-06],</div><div class="">       [  3.49344691e-07,  -1.63000845e-07,   4.27805878e-06, ...,</div><div class="">          5.69157035e-07,   1.44623813e-07,   1.07077057e-07],</div><div class="">       [  1.12878051e-08,   7.65250526e-06,  -3.56727587e-09, ...,</div><div class="">          4.44896483e-08,   5.03697289e-07,   2.19654679e-07],</div><div class="">       ..., </div><div class="">       [  9.13691496e-08,   8.34874369e-08,   6.68844738e-07, ...,</div><div class="">          0.00000000e+00,   4.14336786e-06,   1.54018126e-07],</div><div class="">       [  1.56768727e-06,   1.26927141e-07,   1.86173239e-06, ...,</div><div class="">          1.76178961e-06,  -2.94978281e-06,   2.25371326e-06],</div><div class="">       [  2.13822621e-06,   2.01947558e-08,   6.85551555e-07, ...,</div><div class="">          3.93482720e-07,   8.21207577e-07,   0.00000000e+00]])</div><div class="">>>> type(teMtx)</div><div class=""><type 'numpy.ndarray'></div><div class="">>>> teMtx.size</div><div class="">106929</div><div class="">>>> teMtx.shape</div><div class="">(327, 327)</div><div class=""><div class="">>>> vtk_arr2 = numpy_to_vtk(teMtx)</div><div class="">Traceback (most recent call last):</div><div class="">  File "<stdin>", line 1, in <module></div><div class="">  File "<my-path>/Wrapping/Python/vtk/util/numpy_support.py", line 132, in numpy_to_vtk</div><div class="">    assert z.flags.contiguous, 'Only contiguous arrays are supported.'</div><div class="">AssertionError: Only contiguous arrays are supported.</div></div><div class=""><br class=""></div><div class="">However, the following works fine:</div><div class=""><div class="">>>> m2 = numpy.array([[1.0,2.0],[3.0,4.0]])</div><div class="">>>> type(m2)</div><div class=""><type 'numpy.ndarray'></div></div><div class="">>>> m2.size</div><div class="">4</div><div class="">>>> m2.shape</div><div class="">(2, 2)</div><div class="">>>> vtk_arr_m2 = numpy_to_vtk(m2)</div><div class="">>>></div><div class=""><br></div><div class=""><div class="">>>> vtk.vtkVersion.GetVTKVersion()</div><div class="">'5.7.0'</div></div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><font class="Apple-style-span" face="Courier">teMtx happens to come from a '</font><span style="white-space: pre; " class="Apple-style-span"><font class="Apple-style-span" face="Courier">scipy.io.loadmat', however, via inspection, it appears to be the same as the simpler m2 array.</font></span></div><div class=""><span style="white-space: pre; " class="Apple-style-span"><font class="Apple-style-span" face="Courier"><br class=""></font></span></div><div class=""><span style="white-space: pre; " class="Apple-style-span"><font class="Apple-style-span" face="Courier">thanks, Randy</font></span></div><div class=""><span style="font-family: monospace; white-space: pre; " class="Apple-style-span"><font size="3" class="Apple-style-span"><span style="font-size: 12px;" class="Apple-style-span"><br class=""></span></font></span></div></div>_______________________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtk-developers">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br><br></blockquote></div><br></div></body></html>