<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span id="yui_3_16_0_ym19_1_1502199563234_8037">Re: Brad No unfortunately there's only GetArrayView.. the copy happens at the python level in the wrapping. </span></div><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span><br></span></div><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span id="yui_3_16_0_ym19_1_1502199563234_13019">Re: Samuel, i think you're probably right. </span></div><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span><br></span></div><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span id="yui_3_16_0_ym19_1_1502199563234_12969">I dont think it's a direct issue with the function though, as shown by the second example.</span></div><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span><br></span></div><div id="yui_3_16_0_ym19_1_1502199563234_7959"><span id="yui_3_16_0_ym19_1_1502199563234_12968">Here is something that works:</span></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13030"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13030">vnl_matrix<double> * vnlmat = new vnl_matrix<double>;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13031">vnlmat->set_size(2,3);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13032">vnlmat->fill(0);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13033">vnlmat->put(1,2,1.3);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13034">vnlmat->put(1,0,2);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13036"><br id="yui_3_16_0_ym19_1_1502199563234_13037"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13038">typedef itk::PyVnl<double> PyVnlType;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13039">PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat );</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13039"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13039">Here is something that returns random initialization values (e.g. 1.0232e-307)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13039"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_13039"><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14628">vnl_matrix<double> vnlmat;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14629">vnlmat.set_size(2,3);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14630">vnlmat.fill(0);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14631">vnlmat.put(1,2,1.3);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14632">vnlmat.put(1,0,2);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14634"><br id="yui_3_16_0_ym19_1_1502199563234_14635"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14636">typedef itk::PyVnl<double> PyVnlType;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14637">PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat );</div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14637"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14637"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1502199563234_14637">that's why i say it's a pointer issue . I guess i could just copy the matrix into a new one and use that . i will figure it out. thanks for the help :)</div></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 13px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Tuesday, August 8, 2017 8:51 AM, "Lowekamp, Bradley (NIH/NLM/LHC) [C]" <blowekamp@mail.nih.gov> wrote:<br></font></div>  <br><br> <div class="y_msg_container"><div id="yiv5516187396"><style>#yiv5516187396 #yiv5516187396 --
 
 _filtered #yiv5516187396 {panose-1:2 4 5 3 5 4 6 3 2 4;}
 _filtered #yiv5516187396 {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
 _filtered #yiv5516187396 {panose-1:2 0 5 3 0 0 0 2 0 4;}
#yiv5516187396  
#yiv5516187396 p.yiv5516187396MsoNormal, #yiv5516187396 li.yiv5516187396MsoNormal, #yiv5516187396 div.yiv5516187396MsoNormal
        {margin:0in;margin-bottom:.0001pt;font-size:11.0pt;}
#yiv5516187396 a:link, #yiv5516187396 span.yiv5516187396MsoHyperlink
        {color:blue;text-decoration:underline;}
#yiv5516187396 a:visited, #yiv5516187396 span.yiv5516187396MsoHyperlinkFollowed
        {color:purple;text-decoration:underline;}
#yiv5516187396 span.yiv5516187396EmailStyle17
        {color:windowtext;}
#yiv5516187396 span.yiv5516187396msoIns
        {text-decoration:underline;color:teal;}
#yiv5516187396 .yiv5516187396MsoChpDefault
        {font-size:10.0pt;}
 _filtered #yiv5516187396 {margin:1.0in 1.0in 1.0in 1.0in;}
#yiv5516187396 div.yiv5516187396WordSection1
        {}
#yiv5516187396 </style><div>
<div class="yiv5516187396WordSection1">
<div class="yiv5516187396MsoNormal">Hello,</div> 
<div class="yiv5516187396MsoNormal">  </div> 
<div class="yiv5516187396MsoNormal">Is there a method named something like “_GetArrayFromVnlMatrix”? This should perform a copy of the data, as opposed to just a “view”.</div> 
<div class="yiv5516187396MsoNormal">  </div> 
<div class="yiv5516187396MsoNormal">Brad</div> 
<div class="yiv5516187396MsoNormal">  </div> 
<div class="yiv5516187396MsoNormal">  </div> 
<div class="yiv5516187396yqt0673332064" id="yiv5516187396yqt29653"><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in;">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;"><b><span style="font-size:12.0pt;color:black;">From:
</span></b><span style="font-size:12.0pt;color:black;">Samuel Gerber <samuel.gerber@kitware.com><br clear="none">
<b>Date: </b>Tuesday, August 8, 2017 at 7:57 AM<br clear="none">
<b>To: </b>Nick Cullen <nickmarch31@yahoo.com><br clear="none">
<b>Cc: </b>"insight-users@itk.org" <insight-users@itk.org><br clear="none">
<b>Subject: </b>Re: [ITK] [ITK-users] vnl matrix to numpy array gives random numbers</span></div> 
</div>
<div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;">  </div> 
</div>
<div>
<div class="yiv5516187396MsoNormal" style="margin-right:0in;margin-bottom:12.0pt;margin-left:.5in;">
<span style="">I'd guess there is something funky going with vnl_matrix_fixed. From the docs (
<a rel="nofollow" shape="rect" target="_blank" href="https://github.com/vxl/vxl/blob/master/core/vnl/vnl_matrix_fixed.h">https://github.com/vxl/vxl/blob/master/core/vnl/vnl_matrix_fixed.h</a> ) it says that the data resides on the stack. From your code snippet it is not exactly clear to me who owns the
 data in fixed_matrix, probably image. Might it be that image gets removed before you use the array view?</span></div> 
</div>
<div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;">  </div> 
<div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;">On Mon, Aug 7, 2017 at 10:27 PM, Nick Cullen via Insight-users <<a rel="nofollow" shape="rect" ymailto="mailto:insight-users@itk.org" target="_blank" href="mailto:insight-users@itk.org">insight-users@itk.org</a>> wrote:</div> 
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in;">
<div>
<div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">Hi Friends !!</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">I'm trying to use itkPyVnl directly in ITK, but I must be getting something wrong with pointers... The following
 just gives me random numbers:</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14483">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">```</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14514">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    typedef typename ImageType::DirectionType ImageDirectionType;    </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14515">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    ImageDirectionType * direction = const_cast<ImageDirectionType *>( &image->GetDirection() );</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14516">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14518">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    typedef typename ImageDirectionType::InternalMatrixType DirectionInternalMatrixType;</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14519">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    DirectionInternalMatrixType * fixed_matrix = const_cast<DirectionInternalMatrixType *>( &direction->GetVnlMatrix()
 );</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14520">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14522">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    const vnl_matrix<double> vnlmat1 = fixed_matrix->as_matrix();</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14523">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    vnl_matrix<double> * vnlmat2 = const_cast<vnl_matrix<double> *>( &vnlmat1 );</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14524">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14526">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    typedef itk::PyVnl<double> PyVnlType;</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat2 );</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">```</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">I've tried a million different things and have problems either 1) due to the constness of ->as_matrix() and others
 or 2) due to "taking the address of a temporary object" with ->as_matrix() ... -__-</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">I know that this works:</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14527">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">```</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14561">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    vnl_matrix<double> * vnlmat = new vnl_matrix<double>;</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14562">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    vnlmat->set_size(2,3);</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14563">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    vnlmat->fill(0);</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14564">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    vnlmat->put(1,2,1.3);</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14565">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    vnlmat->put(1,0,2);</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14566">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    std::cout << vnlmat << std::endl;</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14567">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14569">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    typedef itk::PyVnl<double> PyVnlType;</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">    PyObject * mymatrix = PyVnlType::_GetArrayViewFromVnlMatrix( vnlmat );</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">```</span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">  </span></div> 
</div>
<div id="yiv5516187396m_-6518179241648301373yui_3_16_0_ym19_1_1502159025493_14570">
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;background:white;"><span style="font-size:10.0pt;">Any help above is MUCH appreciated !!!!</span></div> 
</div>
</div>
</div>
<div class="yiv5516187396MsoNormal" style="margin-right:0in;margin-bottom:12.0pt;margin-left:.5in;">
<br clear="none">
_____________________________________<br clear="none">
Powered by <a rel="nofollow" shape="rect" target="_blank" href="http://www.kitware.com/">www.kitware.com</a><br clear="none">
<br clear="none">
Visit other Kitware open-source projects at<br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br clear="none">
<br clear="none">
Kitware offers ITK Training Courses, for more information visit:<br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="http://www.kitware.com/products/protraining.php">http://www.kitware.com/products/protraining.php</a><br clear="none">
<br clear="none">
Please keep messages on-topic and check the ITK FAQ at:<br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/ITK_FAQ</a><br clear="none">
<br clear="none">
Follow this link to subscribe/unsubscribe:<br clear="none">
<a rel="nofollow" shape="rect" target="_blank" href="http://public.kitware.com/mailman/listinfo/insight-users">http://public.kitware.com/mailman/listinfo/insight-users</a></div> 
</blockquote>
</div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;"><br clear="none">
<br clear="all">
</div> 
<div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;">  </div> 
</div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;">-- </div> 
<div>
<div>
<div class="yiv5516187396MsoNormal" style="margin-left:.5in;"><span style="font-size:9.5pt;color:#888888;">Samuel Gerber<br clear="none">
R&D Engineer<br clear="none">
Kitware, Inc.</span></div> 
</div>
</div>
</div></div>
</div>
</div></div><br><br></div>  </div> </div>  </div></div></body></html>