'How to add specific values to a list in python?
I want to do a simple plot between x and y where my x is x = np.arange(0,100). My "y" values are mainly 0 but at some places it has a value of 0.5 and 1. Right now I have to write the whole values of y in a list as y = [0,0,0,0,0,0,0,0.5,0.5,0,0,......,1.....0]. Is there a way where I can just write y = np.arange(0,100) to maintain the dimensionality of x and y and then input the specific values of y at the correct place? For example, at 8th position the y value is 0.5. So I want to write y = np.arange(0,100) and then input 0.5 at the 8th position of "y". Otherwise I have to manually write the whole y list. Thank for the help in advance.
Solution 1:[1]
You could just usey = np.zeroes(100)
and then change the specific values just like you would do with lists by y[position where you would like to change] = 0.5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Red Sky |
