This below is a part of my program how do I remove the from the output of this ? can it be removed?
or is it built-in? because I intend to save it as a text file after I convert it to a 2d matrix.
Also, I want to reshape the 1D array "final" as a 2D 30*5 matrix how do I do it (of course there aren't 150 elements here still, it is yet to be added by different main loop)
edited: here stmat is an array of 80 elements and t = 8 for this particular iteration
t = n
t = int(t)
print(t)
import numpy
final = numpy.array
arr = ['1','2','3','5','7']
for p in arr :
sum = 0
p = int(p)
for j in range(t) :
sum = sum + float(stmat[p])
p = p + 10
avg = sum/n
final = numpy.append (final, avg )
print(avg)
print(final)
I get the following output
75.75
[<built-in function array> 75.75]
73.875
[<built-in function array> 75.75 73.875]
93.625
[<built-in function array> 75.75 73.875 93.625]
7.0
[<built-in function array> 75.75 73.875 93.625 7.0]
29.368750000000002
[<built-in function array> 75.75 73.875 93.625 7.0 29.368750000000002]
numpy.array
is a function, final = numpy.array
is assigning the function itself to the variable. Calling final()
now does the same thing as calling numpy.array()
.
If you want to create an initial empty numpy array you should do something like final = numpy.array([])
.
list append is better than np.append
:
final = [] # empty list
arr = ['1','2','3','5','7']
for p in arr :
sum = 0
p = int(p)
for j in range(t) :
sum = sum + float(stmat[p])
p = p + 10
avg = sum/n
final.append( avg )
print(avg)
print(final)
faster and easier to use right.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.