#πŸ”’ mandelbrot set python code help

51 messages Β· Page 1 of 1 (latest)

sharp ruin
#

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!

pure orchidBOT
#

@sharp ruin

Python help channel opened

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.

tawny slate
#

I don't see a array(width, width).

sharp ruin
#

the np.zeros one

tawny slate
#

np.zeros((width, width)) creates a 2d-array with width rows and width columns and initialises every element to 0.0.

sharp ruin
#

why do this?

tawny slate
#

so you have an array where you can store your results.

#

there's no need to initialise it with 0.0. but what else.

sharp ruin
#

hmm so I chuck all the complex numbers in the array? and loop through the array?

tawny slate
#

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.

sharp ruin
#

store the real and complex components?

tawny slate
#

you have complex numbers as inputs.

#

but the result isn't a complex number.

sharp ruin
#

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

tawny slate
#

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.

sharp ruin
#

yes

tawny slate
#

but in your case it's np.linspace(-2.0, 2.0, 1001)

sharp ruin
#

ok

tawny slate
#

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.

sharp ruin
#

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?

tawny slate
#

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.

sharp ruin
#

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

tawny slate
#

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.

sharp ruin
#

theres no more info, maybe I'll just try it

#

why can't I index vals? like vals[0][0] for example

tawny slate
#

you can.

sharp ruin
#

yes i just realised, i wanted to do smth like vals[0][0].replace()

#

but its telling me I can't

tawny slate
#

okay, and then you found out how to do it?

sharp ruin
#

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])?

tawny slate
#

you would just assign vals[0][0] = 12 for example. you can only store a single value in each location.

sharp ruin
#

o

sharp ruin
#

it worked!

#

but why is it orenited like that lol

tawny slate
#

it looks as if you swapped x and y.

sharp ruin
#

alr lemme see

#

i think I fixed it

tawny slate
#

nice

sharp ruin
#

thanks for ur help!

tawny slate
#

you're welcome! lemon_partying

pure orchidBOT
#
Python help channel closed

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.