0

I used numpy as transpose() and also astype(np.double) to the permute function in python but the real question is how i can get a median of every arrays in transposed matrix and make a medaian matrix of each array by itself, (the similar code in matlab is: sinogram=ImMatrix(:,:,6); that used for median function ) and i want it in python. I have this code in matlab:

load('ImMatrix.mat');

ImMatrix = permute(ImMatrix,[2 1 3]);

sinogram=ImMatrix(:,:,6);

sinogram = im2double(sinogram);

that ImMatrix file is a 160*320 uint8 matrix and I want transpose matrix in Python.

Abbas mzs
  • 9
  • 3
  • 1
    Please read [ask] - "doesn't work" isn't a specific problem statement, it's not clear what your issue is here, and why transpose (`.'`) doesn't answer the question in the title – Wolfie Nov 16 '20 at 08:35

1 Answers1

1

Check the doc: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html, it should work.

Check the examples here: How does NumPy's transpose() method permute the axes of an array?

Sometimes, depends of what you want to do with the code, you may need to force a copy in python. For example, if you are using something that reads from the data of the transposed matrix, you need to make a copy first. This is because numpy will only change how you index the underlying data, but not change the data itself. If some third party code takes the variable, and then uses it for computation, the data won't have changed. I think this may be your issue, as your variable is called "sinogram", and most tomography toolboxes do take the underlying data to compute stuff.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120