1

i have a CSV dataset which contains all 7x7 image data. There are 7800 rows and 49 columns. Each row represent one image. The data looks like this. dataset image

I need to apply array to each rows so that i could reshape all the datas into 2D dimension array which have the shape like this but in 7x7. Shape example:

I am using python so what should i do ??

2 Answers 2

1

You can change df into matrix and reshape it:

df.as_matrix().reshape(-1, 7, 7)
0

I'd do it like this:

pd.Series(df.values.reshape(-1, 7, 7).tolist()).apply(np.array)

It's the df.values.reshape(-1, 7, 7) that does the bulk of the work.

array([[[101,  62,  20,   9, 125, 160, 144],
        [214,  66,   0,  25, 170,  93,  51],
        [209,  11,  56,  80, 204, 156, 189],
        [ 95, 211,  26, 172, 207,  39, 249],
        [ 73, 160, 105, 167, 189, 230,  75],
        [ 49, 116, 109, 168, 215, 186,  35],
        [ 68, 154, 185,  12, 186,  78, 252]],

       [[247,  18,  14,  67,  67,  89,  93],
        [110, 174, 139,  88, 123, 131, 254],
        [232,   3,  52,  46, 113,   6, 141],
        [221, 220, 116, 141,  65,  54,  84],
        [203,  51, 222, 204, 237, 121,  80],
        [199,   4, 102, 169,   0, 108, 144],
        [ 23, 249, 127,  20, 226,   2, 214]],

       [[ 22, 188,  68,  65,   4,  32,  33],
        [ 63, 241, 120, 147, 253, 162, 255],
        [158, 228,  18,  56, 193, 232, 183],
        [153,   0, 188, 131,  42, 106, 156],
        [ 51,  70, 219, 156,  94,  50,  43],
        [  0, 130, 203,  47, 245, 108, 250],
        [164, 246, 180,  58, 220, 188,  49]]])
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.