Home > Back-end >  creating a graph using python matplotlib from range(1,100000)
creating a graph using python matplotlib from range(1,100000)

Time:10-13

creating array using numpy from 1 to 100000 as value of x and y = x*x

x = np.arange(1,100000)
y = x*x

but when checked y value there are 31k negative value

count = 0
for i in y:
    if i < 0:
        count =1
print(count)

31612

working on jupyter notebook

https://www.linkedin.com/posts/sandeep-agrawal-3b8857196_python-python3-pythonlearning-activity-6852679546345521152-cG-a

CodePudding user response:

You are probably having integer overflow, try convert x to float before raising the power:

x = np.arange(1,100000)
y = x**10

sum(y < 0)
49760

Convert to float:

x = np.arange(1,100000).astype(float)
y = x**10

sum(y < 0)
0
  • Related