I have been trying to get this program to work using Numpy in Python. Here is my code.
import numpy as np
def function(inNum):
return inNum - 1
i = 1
n = 50000000
AllOutputs = np.array([])
while(i < n):
SingularOutput = np.array([])
num = i
while(num > 1):
print(num)
num = function(num)
np.append(SingularOutput,num)
np.append(AllOutputs,SingularOutput)
i = i + 1
print(i)
The output in the console gives decreasing numbers, here is a snippet.
269
268
267
266
265
264
263
262
261
260
259
258
257
256
255
254
It seems as if is being assigned the values returned from function(inNum), but as it can be seen i is not ever assigned any value other than i = i + 1, thus I do not know why this is happening. Lastly, if I modify the num = i assignment to nums = 1 (or I assume anything else) I get the expected output of
1
2
3
4
5
...(etc)
What am I doing wrong?
np.arange?numpy.appendin a loopnumto 2, followed by the value ofi. Theivalues do increase with each iteration, but most of the output comes from the decreasing sequence.num = 1, you prevent the inner loop from executing at all, so all you see is the increasing values ofiproduced by the outer loop.np.append(SingularOutput,num)doesn't modifySingularOutput. It creates a new array--which you never use. See numpy.org/doc/stable/reference/generated/numpy.append.html