Q: plotting complex function from one set to another For example, I have such set of complex points:

and I want to plot an image of function (for example, f(z) = -cos(z)) from the preimage:

Here is my code for this:
from numpy import *
import matplotlib.pyplot as plt

z_0 = []
N = 500
u = linspace(0.0, pi, N)
v = linspace(0.0, 15.0, N)
for i in xrange(N):
    for j in xrange(N):
        z_0.append(u[i] + 1j * v[j])
z = -cos(z_0)
plt.plot(real(z), imag(z), linestyle='', marker='x')
plt.grid(True)
plt.show()

Can I get rid of two nested loops? Is there any better way to solve the problem using numpy/matplotlib standard functions?

A: You can do it with a one-liner:
import numpy as np
z_0 = u[:,np.newaxis] + 1j*v[np.newaxis,:]

The point is that np.newaxis is a bit of indexing magic which creates (N,1) and (1,N) two-dimensional arrays from the original one-dimensional arrays, which are then duplicated by numpy's indexing rules.

A: You could use numpy.meshgrid:
>>> from numpy import linspace, meshgrid, pi
>>> u = linspace(0, pi, 3)
>>> v = linspace(0, 10, 3)
>>> uu, vv = meshgrid(u, v)
>>> uu
array([[ 0.        ,  1.57079633,  3.14159265],
       [ 0.        ,  1.57079633,  3.14159265],
       [ 0.        ,  1.57079633,  3.14159265]])
>>> vv
array([[  0.,   0.,   0.],
       [  5.,   5.,   5.],
       [ 10.,  10.,  10.]])
>>> z = uu + 1j * vv
>>> z
array([[ 0.00000000 +0.j,  1.57079633 +0.j,  3.14159265 +0.j],
       [ 0.00000000 +5.j,  1.57079633 +5.j,  3.14159265 +5.j],
       [ 0.00000000+10.j,  1.57079633+10.j,  3.14159265+10.j]])

