python - How to set array into float32 data type (need to be compatible with append)? -


i ran problem float 32 arrays. basically, have defined function , want produce series of results in array forms, called "apoints" in following code. found if use array([],numpy.float32), append commands, 'numpy.ndarray' object has no attribute 'append' .

does know do? many thanks!

### here code, , apoints result in 64 bits, not 32.
def f(n):         s = np.float32(0)         n in arange(1,n+1,1,dtype=np.float32):  #for upward summation             #print s             s = np.float32(np.float32(s) + np.float32(np.float32(1.0)/(np.float32((np.float32(n)*np.float32(n))))))         return np.float32(np.float32(abs(np.float32((np.float32(s)-np.float32(r)))))/np.float32(r))   npoints = [] apoints = [] hpoints = []  npoints = arange(10,1000,20,dtype=np.float32)  n in npoints:     apoints.append(np.float32(f(n)))     hpoints.append(np.float32(np.float32(1.0)/(np.float32(n))))  print apoints 

'numpy.ndarray' object has no attribute 'append'

-> trying call append() on numpy array type ndarray has no append method. explanation simple: arrays immutable, not make sense have appending stuff on numpy ndarray object.

appending arrays functionality provided directly in numpy. creates new array values (old , appended ones).

a = numpy.array( [1,2,3] ) b = numpy.array( [4,5,6] ) c = numpy.append(a,b) print c 

this generates following output:

array([1, 2, 3, 4, 5, 6]) 

numpy.append(a,b) creates new array of dimension equal dimension of plus dimension of b, new array can hold values of and b. new array return, can save c.

for further explanations lookup numpy documentation or start new questions ;)


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -