As a C ++ programmer, I am used to access vectors in C ++ style:
for (i = 0; i & Lt; max_x; i ++) {for (j = 0; j & lt; max_y; j ++) {vec [i] [j] = real (complex_number (j + i * max_x))}} Now I have Python
x = np.linspace (x1, x2, phase) y = np.linspace (y1, y2, phase) x, In Y for Z = Np.meshgrid (x, y) Z = x + 1j * z: FZ = complex_function (z) I have the same thing as the C ++ code How can I accomplish a "dragon" way? Thanks
EDIT: Checking the functions of the new shape and reconnecting my code, I mentioned a problem with the changes and backs for the 1D arrays from 2D arrays. The main problem is that I have a function that accepts a complex array z_list and returns a complex array. I need to plot on that grid, and I was planning to use matplotlib, but matplotlib needs 2d head with every point of that array that is worth i have to do without generating 2d array Can I turn it into 1D array, and again give the array a new shape again on 2D? Thank you.
Use 1D array to turn on 2D (or any other shape).
& gt; & Gt; & Gt; X_max = 12> gt; & Gt; & Gt; Y_max = 4> gt; & Gt; & Gt; Vec1d = np.arange (x_max * y_max, dtype = complex) & gt; & Gt; & Gt; Vec1d.reshape ([x_max, y_max]) array ([0. + 0.j, 1. + 0.j, 2. + 0.j, 3. + 0.j], [4. + 0.j, 5. + 0.j, 6. + 0.j, 7. + 0.j], [8. + 0.j, 9 + 0.j, 10. + 0.j, 11. + 0J], [12. + 0.j, 13. + 0.j, 14. + 0.j, 15. + 0.j], [16. + 0.j, 17. + 0.j, 18 + 0.j , 19. + 0.j], [20. + 0.j, 21. + 0.j, 22. + 0.j, 23. + 0.j], [24. + 0.J, 25. + 0. J, 26. + 0. J, 27. + 0. J], [28. + 0.j, 29. + 0.j, 30. + 0.j, 31. + 0], [32] . + 0.j, 33. + 0.j, 34. + 0.j, 35. + 0.j], [36. + 0.j, 37. + 0, 38 + 0.j, 39 . + 0.j], [40. + 0.j, 41. + 0.j, 42. + 0.j, 43. + 0.j], [44. + 0.j, 45. + 0. J, 46. + 0.j, 47. + 0.j]])
Comments
Post a Comment