Wednesday, 15 April 2015

python - 400*1 cells in original data, 64*64 matrix in each cell, how to stretch the data into column vectors and form a 4096*400 matrix? -


I'm new to Python and now I have a problem in my assignment. There is a basic dataset in this dataset, 400 cells. In each cell, there are 64 * 64 matrix.

  array ([[array ([, 75, 89, 101, ..., 90, 80, 74], [83, 98, 106, ..., 90, 82, 76], [83, 101, 109, ..., 92, 82, 72] ..., [52, 50, 54, ..., 37, 40, 42], [49, 51, 51,. .., 36, 39, 40], [49, 50, 49, ..., 37, 39, 38]], dtype = uint8), array ([[110, 114, 124, ..., 46, 45, 45], [108, 117, 126, ..., 52, 51, 51], [120, 125, 129, ..., 49, 50, 50], ..., [187, 18] 9, 192, ..., 35, 35, 35], [187, 188, 1 9 1, ..., 33, 33, 33], [185, 1 9, 18, 9 ... , [37, 37, 37]], dtype = uint8, array ([[77, 97, 119, ..., 97, 86, 75], [75, 96, 116, ..., 98, 91, 73], [65, 84, 110, ..., 96, 90, 75] ..., [32, 24, 20, ..., 33, 36, 37], [28, 23, 19, ..., 35, 35, 38], [27, 22, 19, ..., 34, 36, 37]], dtype = uint8),  

(among them 400) I want to spread the data into column vectors and make a matrix In the new matrix, a cell of the original data in each column vector contains 64 * 64 = 4096 data and thus I could get a 4096 * 400 matrix.

Thank you ...

Your question will need to resize your array and then transfer it to:

In
  [28]: a = np.arange (3 * 4 * 2). Renewal (3,1, [49]: One out [29]: Array ([[[0, 1], [2, 3], [4, 5], [6, 7]], [ [[8, 9], [10, 11], [12, 13], [14, 15]], [[16, 17], [18, 19], [20, 21], [22, 23 ]]] In [30]: a.reshape (a.shape [0], a.shape [-2] * a.shape [-1] t out [30]: array ([[0, 8, [6, 14, 22] [4, 12, 20], [5, 13, 21], [1, 9, 17], [2, 10, 18], [3, 11, 19] [6, 14, 22]], [7, 15, 23]] As David said in the comments, if you want to anoint 64x64 matrix column-wise, then  Fortran  in the  reshape : 

  in [31]: a.reshape ((a.shape [0], a.shape [-2] * A TT [31]: Array ([[0, 8, 16], [2, 10, 18], [4, 12, 20], [6, 14, 22], [1, 9, 17] , [3, 11, 19], [5, 13, 21], [7, 15, 23]])   

However, how do you get your data to be printed with the array in that form ([[array ([[[ is unusual and there is nothing that I immediately How to you did. You might want to consider changing the way to generate that dataset: If the number of 64x64 "matrix" is pre-known, you can create an array ( np .rempty (400, 64, 64) ) and then fill it Otherwise, a normal Python The list will be enough, for which you can add each new 64x64 matrix and finally change the list of arrays in a full array ( np.array (list_of_matrices) ).


No comments:

Post a Comment