I need to fill in the functions defined here, but I'm not entirely sure what they mean. Can someone help?
I interpret the function index_to_position function as in the second picture, is that right? Each of the yellow dots represents complex numbers that I'm gonna check if its in the mandelbrot set.
Not sure what the array(width, width) is meant to do though.
Any help is appreciated!
#π mandelbrot set python code help
51 messages Β· Page 1 of 1 (latest)
@sharp ruin
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
I don't see a array(width, width).
the np.zeros one
np.zeros((width, width)) creates a 2d-array with width rows and width columns and initialises every element to 0.0.
why do this?
so you have an array where you can store your results.
there's no need to initialise it with 0.0. but what else.
hmm so I chuck all the complex numbers in the array? and loop through the array?
i think you can't store complex numbers in that array. it's a float64 array.
so you can only store real numbers in it.
store the real and complex components?
yea
so what do I do with that array I'm confused. It's in this block of code which I don't know what it means
np.linspace(0.0, 1.0, 5) would create an np.array([0.0, 0.25, 0.5, 0.75, 1.0])
5 evenly spaced numbers between 0 and 1 in that case.
yes
but in your case it's np.linspace(-2.0, 2.0, 1001)
ok
this block of code is just for drawing the diagram. and the np.linspace(-2.0, 2.0, 1001) is used for the axis labels.
vals only includes the values, so it's necessary to pass the coordinates of the values extra, to draw a nice diagram.
i searched up plt.contour and it said the parameter z, which I guess is the "vals" in my code, is the height values over which the contour is drawn, but vals is just an array of 0's?
yes, the vals are the heights. it's a height diagram like a map where it shows the mountains.
initially your vals are all 0.0. so you need to calculate the "heights" and replace the 0.0s with the correct values.
should I be replacing the 0's in the array with the number of iterations it took for z to diverge? z as in z=z*z+c
maybe that is correct. probably you can find that info in the description of your assignment.
i think there are many different ways to fill the vals.
theres no more info, maybe I'll just try it
why can't I index vals? like vals[0][0] for example
you can.
yes i just realised, i wanted to do smth like vals[0][0].replace()
but its telling me I can't
okay, and then you found out how to do it?
not yet, I'm searching
np.put(a, [0, 2], [-44, -55]) like this right I found it online
but how do i do it for a two d array? what would [0,2] become if i want to replace ith row and jth coloumn element? like np.put(a, [i][j], [-44, -55])?
you would just assign vals[0][0] = 12 for example. you can only store a single value in each location.
o
it looks as if you swapped x and y.
nice
thanks for ur help!
you're welcome! 
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.