def clpmn(m,n,z,type=<NUM_LIT:3>):
if not isscalar(m) or (abs(m) > n):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(n) or (n < <NUM_LIT:0>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isscalar(z):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not(type == <NUM_LIT:2> or type == <NUM_LIT:3>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (m < <NUM_LIT:0>):<EOL><INDENT>mp = -m<EOL>mf,nf = mgrid[<NUM_LIT:0>:mp+<NUM_LIT:1>,<NUM_LIT:0>:n+<NUM_LIT:1>]<EOL>sv = errprint(<NUM_LIT:0>)<EOL>if type == <NUM_LIT:2>:<EOL><INDENT>fixarr = where(mf > nf,<NUM_LIT:0.0>, (-<NUM_LIT:1>)**mf * gamma(nf-mf+<NUM_LIT:1>) / gamma(nf+mf+<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>fixarr = where(mf > nf,<NUM_LIT:0.0>,gamma(nf-mf+<NUM_LIT:1>) / gamma(nf+mf+<NUM_LIT:1>))<EOL><DEDENT>sv = errprint(sv)<EOL><DEDENT>else:<EOL><INDENT>mp = m<EOL><DEDENT>p,pd = specfun.clpmn(mp,n,real(z),imag(z),type)<EOL>if (m < <NUM_LIT:0>):<EOL><INDENT>p = p * fixarr<EOL>pd = pd * fixarr<EOL><DEDENT>return p,pd<EOL>
Associated Legendre function of the first kind, Pmn(z)

    Computes the (associated) Legendre function of the first kind
    of order m and degree n,::

        Pmn(z) = P_n^m(z)

    and its derivative, ``Pmn'(z)``.  Returns two arrays of size
    ``(m+1, n+1)`` containing ``Pmn(z)`` and ``Pmn'(z)`` for all
    orders from ``0..m`` and degrees from ``0..n``.

    Parameters
    ----------
    m : int
       ``|m| <= n``; the order of the Legendre function.
    n : int
       where ``n >= 0``; the degree of the Legendre function.  Often
       called ``l`` (lower case L) in descriptions of the associated
       Legendre function
    z : float or complex
        Input value.
    type : int
       takes values 2 or 3
       2: cut on the real axis |x|>1
       3: cut on the real axis -1<x<1 (default)

    Returns
    -------
    Pmn_z : (m+1, n+1) array
       Values for all orders 0..m and degrees 0..n
    Pmn_d_z : (m+1, n+1) array
       Derivatives for all orders 0..m and degrees 0..n

    See Also
    --------
    lpmn: associated Legendre functions of the first kind for real z

    Notes
    -----
    By default, i.e. for ``type=3``, phase conventions are chosen according
    to [1]_ such that the function is analytic. The cut lies on the interval
    (-1, 1). Approaching the cut from above or below in general yields a phase
    factor with respect to Ferrer's function of the first kind
    (cf. `lpmn`).

    For ``type=2`` a cut at |x|>1 is chosen. Approaching the real values
    on the interval (-1, 1) in the complex plane yields Ferrer's function
    of the first kind.

    References
    ----------
    .. [1] NIST Digital Library of Mathematical Functions
           http://dlmf.nist.gov/14.21