<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dir2cart(d):
 # from pmag.py """converts list or array of vector directions, in degrees, to array of cartesian coordinates, in x,y,z form """

    ints = numpy.ones(len(d)).transpose() # get an array of ones to plug into dec,inc pairs             
    d = numpy.array(d)
    rad = old_div(numpy.pi, 180.)
    if len(d.shape) > 1: # array of vectors                                                         
        decs, incs = d[:,0] * rad, d[:,1] * rad
        if d.shape[1] == 3: ints = d[:,2] # take the given lengths                  
    else: # single vector                                 
        decs, incs = numpy.array(d[0]) * rad, numpy.array(d[1]) * rad
        if len(d) == 3:
            ints = numpy.array(d[2])
        else:
            ints = numpy.array([1.])
    cart = numpy.array([ints * numpy.cos(decs) * numpy.cos(incs),
                       ints * numpy.sin(decs) * numpy.cos(incs),
                       ints * numpy.sin(incs)
                     ]).transpose()
    return cart