<p dir="auto">Multiplying a <code class="notranslate">np.float64</code>, <code class="notranslate">np.float32</code> or <code class="notranslate">np.float16</code> by a string gives an empty string, but doing the same with a <code class="notranslate">np.float</code> or a <code class="notranslate">np.float128</code> raises an error:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Python 3.4.4 |Anaconda 2.3.0 (x86_64)| (default, Jan  9 2016, 17:30:09) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; np.float64(0.5) * 'hello'
''
&gt;&gt;&gt; np.float16(0.5) * 'hello'
''
&gt;&gt;&gt; np.float32(0.5) * 'hello'
''
&gt;&gt;&gt; np.float128(0.5) * 'hello'
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: can't multiply sequence by non-int of type 'numpy.float128'
&gt;&gt;&gt; np.float(0.5) * 'hello'
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: can't multiply sequence by non-int of type 'float'"><pre class="notranslate"><span class="pl-v">Python</span> <span class="pl-c1">3.4</span><span class="pl-c1">.4</span> <span class="pl-c1">|</span><span class="pl-v">Anaconda</span> <span class="pl-c1">2.3</span><span class="pl-c1">.0</span> (<span class="pl-s1">x86_64</span>)<span class="pl-c1">|</span> (<span class="pl-s1">default</span>, <span class="pl-v">Jan</span>  <span class="pl-c1">9</span> <span class="pl-c1">2016</span>, <span class="pl-c1">17</span>:<span class="pl-c1">30</span>:<span class="pl-c1">09</span>) 
[<span class="pl-v">GCC</span> <span class="pl-c1">4.2</span><span class="pl-c1">.1</span> (<span class="pl-v">Apple</span> <span class="pl-v">Inc</span>. <span class="pl-s1">build</span> <span class="pl-c1">5577</span>)] <span class="pl-s1">on</span> <span class="pl-s1">darwin</span>
<span class="pl-v">Type</span> <span class="pl-s">"help"</span>, <span class="pl-s">"copyright"</span>, <span class="pl-s">"credits"</span> <span class="pl-c1">or</span> <span class="pl-s">"license"</span> <span class="pl-k">for</span> <span class="pl-s1">more</span> <span class="pl-s1">information</span>.
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">float64</span>(<span class="pl-c1">0.5</span>) <span class="pl-c1">*</span> <span class="pl-s">'hello'</span>
<span class="pl-s">''</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">float16</span>(<span class="pl-c1">0.5</span>) <span class="pl-c1">*</span> <span class="pl-s">'hello'</span>
<span class="pl-s">''</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">float32</span>(<span class="pl-c1">0.5</span>) <span class="pl-c1">*</span> <span class="pl-s">'hello'</span>
<span class="pl-s">''</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">np</span>.<span class="pl-en">float128</span>(<span class="pl-c1">0.5</span>) <span class="pl-c1">*</span> <span class="pl-s">'hello'</span>
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
<span class="pl-v">TypeError</span>: <span class="pl-s1">can</span><span class="pl-s">'t multiply sequence by non-int of type '</span><span class="pl-s1">numpy</span>.<span class="pl-s1">float128</span><span class="pl-s">'</span>
<span class="pl-s">&gt;&gt;&gt; np.float(0.5) * '</span><span class="pl-s1">hello</span>'
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
<span class="pl-v">TypeError</span>: <span class="pl-s1">can</span><span class="pl-s">'t multiply sequence by non-int of type '</span><span class="pl-s1">float</span>'</pre></div>
<p dir="auto">I would expect these to all give the same result - and, personally, I would expect that result to be raising an exception.</p>
<p dir="auto">(For context: I was bitten by this when I had a nasty bug in some of my own code. The bug was - of course - entirely my own fault, but a <code class="notranslate">np.float64</code> not raising an exception when multiplied by a string made the bug quite hard to track down)</p>
<p dir="auto">This illustrates the issue:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np 
&gt;&gt;&gt; print 'x'*np.float64(3.5)"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span> 
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">print</span> <span class="pl-s">'x'</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-en">float64</span>(<span class="pl-c1">3.5</span>)</pre></div>
<p dir="auto">The same construction using a regular python float raises a <code class="notranslate">TypeError</code>, as I would expect:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; 'x'*3.5
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: can't multiply sequence by non-int of type 'float'"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s">'x'</span><span class="pl-c1">*</span><span class="pl-c1">3.5</span>
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
<span class="pl-v">TypeError</span>: <span class="pl-s1">can</span><span class="pl-s">'t multiply sequence by non-int of type '</span><span class="pl-s1">float</span>'</pre></div>
<p dir="auto">I haven't looked very closely at the implementation of the numpy float class. Please feel free to close this issue if this is working as expected.</p>
<p dir="auto">This is on numpy 1.9.2 and python 2.7.9</p>