a=np.arange(10,49)
b=np.array([])
for num in range(len(a)//2,-1):
b=np.append(a[num])
print(b)
This still gives an empty array as output.
Need Help.
a=np.arange(10,49)
b=np.array([])
for num in range(len(a)//2,-1):
b=np.append(a[num])
print(b)
This still gives an empty array as output.
Need Help.
There are two Poblems with your code if you want that all the elements of a get added in b
The for loop is never been runnedâ€¦
As your array a has length 39 then len(a)//2 is 19 and your range would becomeâ€¦(19, -1) and that is nothingâ€¦just go ahead and try to do thisâ€¦
for i in range(19, -1): print(i)
Youâ€™ll get nothingâ€¦Hope you understandâ€¦
The append function that youâ€™ve used is not implemented correctlyâ€¦
I think you have some problem in append method of numpyâ€¦
The append method basically takes two arguements (for your purpose only otherwise it takes 3) first arguement is in which array you want to appendâ€¦so in your case that would be b and second arguement is the values which in your case is a single value ( but there can be more than value appended)â€¦so you would give second arguement as [a[num]]
â€¦which would be considered as an array with single elementâ€¦and then it will return that array which you are storing in b which is correctâ€¦
Hope this helps to solve your problemâ€¦
Thank you
Thanks for your help.