<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fromrdd(rdd, dims=None, nrecords=None, dtype=None, labels=None, ordered=False):
 """ Load images from a Spark RDD. Input RDD must be a collection of key-value pairs where keys are singleton tuples indexing images, and values are 2d or 3d ndarrays. Parameters rdd : SparkRDD An RDD containing the images. dims : tuple or array, optional, default = None Image dimensions (if provided will avoid check). nrecords : int, optional, default = None Number of images (if provided will avoid check). dtype : string, default = None Data numerical type (if provided will avoid check) labels : array, optional, default = None Labels for records. If provided, should be one-dimensional. ordered : boolean, optional, default = False Whether or not the rdd is ordered by key """

    from .images import Images
    from bolt.spark.array import BoltArraySpark

    if dims is None or dtype is None:
        item = rdd.values().first()
        dtype = item.dtype
        dims = item.shape

    if nrecords is None:
        nrecords = rdd.count()

    def process_keys(record):
        k, v = record
        if isinstance(k, int):
            k = (k,)
        return k, v

    values = BoltArraySpark(rdd.map(process_keys), shape=(nrecords,) + tuple(dims), dtype=dtype, split=1, ordered=ordered)
    return Images(values, labels=labels)