How can I translate these Matlab statistics into Python?

조회 수: 3 (최근 30일)
Mahreen Kohkar
Mahreen Kohkar 2022년 9월 3일
답변: Al Danial 2022년 9월 7일
I am trying to write an equivalent Matlab program to Python. Can someone help with an equivalent Python statement for the mentioned statement?
Yd = fread(fid,[3840 2160],'ubit16'); Y{i} = Yd';

답변 (1개)

Al Danial
Al Danial 2022년 9월 7일
If this 3840 x 2160 matrix is the only data in the file you could do
import numpy as np
Yd = np.fromfile('file_with_matrix.bin', dtype=np.uint16).reshape(2160,3840).T
Y[i] = Yd.T
Note that both the 2nd and 3rd lines have transposes (.T). The 2nd line compensates for MATLAB's column-major reading compared to NumPy's row-major. You could instead do
import numpy as np
Y[i] = np.fromfile('file_with_matrix.bin', dtype=np.uint16).reshape(3840,2160)
Yd = Y[i].T
and only tranpose once.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by