float precision in numpy arrays differ from their elements
<p>I have values of <code>numpy.float32</code> type, and a numpy array with <code>dtype="float32"</code>.</p>

<p>When outputting the representation of the values directly using the individual array element references, I get a difference in precision than when I output the representation of the array object itself.</p>

<p>The ensuing calculations are also a bit off, so the latter value seems to be the one used in consequtive vector / matrix artihmetic.</p>

<p>Why is there a difference, and must these precision "anomalies" be handled manually?</p>

<pre><code>&gt;&gt;&gt; a = math.pi / 2

&gt;&gt;&gt; a
1.5707963267948966

&gt;&gt;&gt; elementx = numpy.float32(math.cos(a))

&gt;&gt;&gt; arrayx = numpy.array([elementx], dtype="float32")

&gt;&gt;&gt; elementx
6.1232343e-17

&gt;&gt;&gt; arrayx
array([  6.12323426e-17], dtype=float32)

&gt;&gt;&gt; t = numpy.float32(3.0)

&gt;&gt;&gt; t * elementx
1.8369703e-16

&gt;&gt;&gt; t * arrayx
array([  1.83697028e-16], dtype=float32)
</code></pre>

<p>(Python 3.5.2, GCC 5.4.0, linux 4.4.0-21-generic)</p>

<p>These are just differences in the string representation, the values are the same and calculations are not off.</p>

<pre><code>&gt;&gt;&gt; (t * elementx) == (t * arrayx)[0]
True
</code></pre>

python numpy floating-point precision