<p dir="auto">If a single element array is passed to <code class="notranslate">np.float64()</code> in the following way, it is returned not as an array but as a numpy scalar.  I have not observed this behavior when converting in this way via other dtypes, though my tests are not exhaustive.  Code to reproduce below:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np

# Returns float 0.699..., not array([0.699])
np.float64(np.array([0.7], dtype=np.float64))

# Broken for conversion within floats; returns 0.5
np.float64(np.array([0.5], dtype=np.float32))

# Broken for conversion from uint; returns 42.0
np.float64(np.array([42], dtype=np.uint8))

# Works as expected for 2-element arrays
np.float64(np.array([0.7, 0.7], dtype=np.float64))

# np.float32() and np.uint8() properly return arrays
np.float32(np.array([0.7], dtype=np.float64)  # array([0.699], dtype=float32)
np.uint8(np.array([42.], dtype=np.float64)    # array([4], dtype=uint8)"><pre class="notranslate"><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-c"># Returns float 0.699..., not array([0.699])</span>
<span class="pl-s1">np</span>.<span class="pl-en">float64</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.7</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float64</span>))

<span class="pl-c"># Broken for conversion within floats; returns 0.5</span>
<span class="pl-s1">np</span>.<span class="pl-en">float64</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.5</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float32</span>))

<span class="pl-c"># Broken for conversion from uint; returns 42.0</span>
<span class="pl-s1">np</span>.<span class="pl-en">float64</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">42</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>))

<span class="pl-c"># Works as expected for 2-element arrays</span>
<span class="pl-s1">np</span>.<span class="pl-en">float64</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.7</span>, <span class="pl-c1">0.7</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float64</span>))

<span class="pl-c"># np.float32() and np.uint8() properly return arrays</span>
<span class="pl-s1">np</span>.<span class="pl-s1">float32</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.7</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float64</span>)  <span class="pl-c"># array([0.699], dtype=float32)</span>
<span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">42.</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float64</span>)    <span class="pl-c"># array([4], dtype=uint8)</span></pre></div>
<p dir="auto">This was observed on both NumPy 1.6.1 and 1.6.2.  I realize a workaround is to use the <code class="notranslate">.astype()</code> method, and that would probably be more correct.  However, this functionality is exposed and I do not believe it is expected behavior.</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/764" rel="nofollow">http://projects.scipy.org/numpy/ticket/764</a> on 2008-04-29 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/charris/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/charris">@charris</a>, assigned to unknown.</em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: float32(array([[1]]))
Out[1]: array([[ 1.]], dtype=float32)

In [2]: float64(array([[1]]))
Out[2]: 1.0

In [3]: int64(array([[1]]))
Out[3]: array([[1]], dtype=int64)

In [4]: int32(array([[1]]))
Out[4]: 1"><pre class="notranslate"><code class="notranslate">In [1]: float32(array([[1]]))
Out[1]: array([[ 1.]], dtype=float32)

In [2]: float64(array([[1]]))
Out[2]: 1.0

In [3]: int64(array([[1]]))
Out[3]: array([[1]], dtype=int64)

In [4]: int32(array([[1]]))
Out[4]: 1
</code></pre></div>
<p dir="auto">But also</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [5]: float64([[1]])
Out[5]: array([[ 1.]])

In [6]: int32([[1]])
Out[6]: array([[1]])"><pre class="notranslate"><code class="notranslate">In [5]: float64([[1]])
Out[5]: array([[ 1.]])

In [6]: int32([[1]])
Out[6]: array([[1]])
</code></pre></div>