2016-08-26 5 views
0

Ich versuche, einen Spark-Datenframe zu erhalten, traindf in ein 4-d-numpy-Array. Ich habe dies versucht:Pyspark-Datenframe in 4-dimensionales numpy Array umwandeln für Keras/Theano

traindf = sqlContext.createDataFrame([ 
    (1, 1, 2, 3), 
    (1, 2, 2, 3), 
    (1, 3, 2, 3), 
    (1, 4, 2, 3), 
    (2, 4, 5, 6), 
    (2, 4, 5, 6), 
    (3, 7, 8, 9), 
    (2, 4, 5, 6), 
    (3, 7, 8, 9), 
    (3, 7, 8, 9) 
], ("id", "image", "s", "t")) 

values = (traindf.rdd.map(lambda l: [map(lambda r: float(r), l)]).collect()) 
x = np.array(values) 
x = np.array_split(x, x.shape[0]/2) 
x = np.asarray(x) 
x.shape 

Diese Ausbeuten (5, 2, 1, 4), aber es scheint keras Bedürfnisse (5, 1, 2, 4). Ich habe ein paar Wege ausprobiert, sehe aber keinen guten Weg, das richtige Format zu bekommen.

Irgendwelche Vorschläge?

Antwort

0

Nur es herausgefunden, heften diese auf das Ende

x = np.reshape(x, (5, 1, 2, 4))