Matlab vs Python: Reshape

后端 未结 2 387
说谎
说谎 2020-12-30 00:58

So I found this:

When converting MATLAB code it might be necessary to first reshape a matrix to a linear sequence, perform some indexing operations

2条回答
  •  独厮守ぢ
    2020-12-30 01:48

    I was having a similar issue myself, as I am also trying to make the transition from MATLAB to Python. I was finally able to convert a numpy matrix, given in depth, row, col, format to a single sheet of column vectors (per image).

    In MATLAB I would have done something like:

    output = reshape(imStack,[row*col,depth])
    

    In Python this seems to translate to:

    import numpy as np
    output=np.transpose(imStack)
    output=output.reshape((row*col, depth), order='F')
    

提交回复
热议问题