<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><font class="Apple-style-span" size="4">Hello All,</font><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4">It seems that flex arrays do not support slice assignment:</font></div><div><font class="Apple-style-span" size="4"><br></font></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="Monaco">py&gt; from scitbx.array_family import flex</font></div></div><div><div><font class="Apple-style-span" face="Monaco">py&gt; ary = flex.float(range(5))</font></div></div><div><div><font class="Apple-style-span" face="Monaco">py&gt; list(ary)</font></div></div><div><div><font class="Apple-style-span" face="Monaco">[0.0, 1.0, 2.0, 3.0, 4.0]</font></div></div><div><div><font class="Apple-style-span" face="Monaco"><div>py&gt; ary[:3] = flex.float([41, 42, 43])</div><div>---------------------------------------------------------------------------</div><div>ArgumentError &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Traceback (most recent call last)</div><div>/usr/local/cctbx/cctbx_sources/mmtbx/dynamics/&lt;ipython-input-13-5ce3d648bc6f&gt; in &lt;module&gt;()</div><div>----&gt; 1 ary[:3] = flex.float([41, 42, 43])</div><div><br></div><div>ArgumentError: Python argument types in</div><div>&nbsp; &nbsp; float.__setitem__(float, slice, float)</div><div>did not match C++ signature:</div><div>&nbsp; &nbsp; __setitem__(scitbx::af::versa&lt;float, scitbx::af::flex_grid&lt;scitbx::af::small&lt;long, 10ul&gt; &gt; &gt; {lvalue}, scitbx::af::small&lt;long, 10ul&gt;, float)</div><div>&nbsp; &nbsp; __setitem__(scitbx::af::versa&lt;float, scitbx::af::flex_grid&lt;scitbx::af::small&lt;long, 10ul&gt; &gt; &gt; {lvalue}, long, float)</div></font></div></div></blockquote><div><div><span class="Apple-style-span" style="font-size: large; "><br></span></div><div><span class="Apple-style-span" style="font-size: large; ">Slice assignment is common in python:</span></div><div><font class="Apple-style-span" size="4"><br></font></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="Monaco">py&gt; alist = range(5)</font></div></div><div><div><font class="Apple-style-span" face="Monaco">py&gt; alist[:3] = [41, 42, 43]</font></div></div><div><div><font class="Apple-style-span" face="Monaco">py&gt; alist</font></div></div><div><div><font class="Apple-style-span" face="Monaco">[41, 42, 43, 3, 4]</font></div></div></blockquote><div><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4">Is there a flex array work-alike for this operation?</font></div><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4">I've found set_selected():</font></div><div><font class="Apple-style-span" size="4"><br></font></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><font class="Apple-style-span" face="Monaco">py&gt; sel_ary = flex.bool([True, True, True, False, False])</font></div></div></div><div><div><div><font class="Apple-style-span" face="Monaco">py&gt; ary.set_selected(sel_ary, flex.float([41, 42, 43]))</font></div></div></div><div><div><div><font class="Apple-style-span" face="Monaco">&lt;scitbx_array_family_flex_ext.float at 0x101df1158&gt;</font></div></div></div><div><div><div><font class="Apple-style-span" face="Monaco">py&gt; list(ary)</font></div></div></div><div><div><div><font class="Apple-style-span" face="Monaco">[41.0, 42.0, 43.0, 3.0, 4.0]</font></div></div></div></blockquote><div><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4">But set_selected() is cumbersome for slice assignment because (1) you have to build a flex selection array somehow and (2) you have to put the new values into a flex array of the appropriate type. Is set_selected() the best way? If so, is there something in the cctbx libraries that makes building "slicing" selection arrays more efficient than say a list comprehension?</font></div><div><font class="Apple-style-span" size="4"><br></font></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font class="Apple-style-span" face="Monaco">sel_ary = flex.bool([True if i &lt; 3 else False for i in xrange(5)])</font></div></div></blockquote><div><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4">James</font></div><div><font class="Apple-style-span" size="4"><br></font></div><div><font class="Apple-style-span" size="4"><br></font></div><div apple-content-edited="true"><font class="Apple-style-span" size="4"><br class="Apple-interchange-newline">
</font></div>
<br></div></body></html>