Really weird numpy array floating point behavior

I am working with numpy for the first time and am experiencing some very strange problems with floating point arrays.

It is very simple, and I probably do not see anything obvious here - can anyone tell me what the problem is?

These two lines of code

arr1 = numpy.ndarray([1.0, 2.0])
print "arr1: ", arr1

output this conclusion:

arr1:  [[  1.49166815e-154  -1.32750723e-315]]

It is not right. What am I doing wrong?

Thanks for the help!

+3
source share
2 answers

You should use numpy.arrayto create an array, not numpy.ndarray. numpy.ndarray- This is a low-level interface, and in most cases numpy.arrayshould be used to create an array.

In [5]: arr1 = numpy.array([1.0, 2.0])                                                            

In [6]: arr1
Out[6]: array([ 1.,  2.])

Signature numpy.ndarray:

ndarray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)         

, shape . , numpy .

docstring numpy.ndarray:

array, zeros empty.

+4

, , - . , buffer.

np.ndarray(shape=(1,2), buffer=np.array([1,2]), dtype=float)
+2

All Articles