graficador/graficador.py at master · antonioam82/graficador · GitHub

work in progress...

Python: Issue reading in str from MATLAB .mat file using h5py and NumPy

I am having difficulty loading in 'str' variables 'Et' (Endtime) and 'St' (Starttime) from a MATLAB .mat file into Python.

I want identical output as in MATLAB. Instead I have had issues trying to solve this. See below for Python code and output.

# Import numpy and h5py to load in .mat files
import numpy as np
import h5py 
Load in Matlab ('-v7.3') data

fname = 'directory/file.mat'
f = h5py.File(fname,'r')

create dictionary for data

data= {"average":np.array(f.get('average')),"median":np.array(f.get('median')),
"stdev":np.array(f.get('stdev')),"P10":np.array(f.get('p10')),
"P90":np.array(f.get('p90')),"St":np.str(f.get('stime')),
"Et":np.str(f.get('etime'))}

All other variables are arrays

print(data["Et"])

output:

<HDF5 dataset "etime": shape (1, 6), type "<u4">

I want to have a string in python equal to the string in MATLAB. In other words, I want print(data["Et"]) = '01011212000000' which is the date and time.

How can I solve this?

MATLAB Numpy element wise multiplication issue

Please see the MATLAB code and equivalent Numpy code below. Question: How can I get the D variable same in Numpy as MATLAB's?

Please see the MATLAB code and equivalent Numpy code below. Question: How can I get the D variable same in Numpy as MATLAB's?

MATLAB Code

A = [1 2 3; 4 5 6; 7 8 9]

C = [100 1; 10 0.1; 1, 0.01]

C = reshape(C, 1,3,2)

D = bsxfun(@times, A, C)

D(:,:,1) =

   100    20     3
   400    50     6
   700    80     9

D(:,:,2) =

1.0000    0.2000    0.0300
4.0000    0.5000    0.0600
7.0000    0.8000    0.0900

Numpy Code

A = np.array([[1,2,3],[4,5,6],[7,8,9]])

C = np.array([[[100, 1], [10, 0.1], [1, 0.01]]]) # C.shape is (1, 3, 2)

D = A * C.T

D

array([[[100.  , 200.  , 300.  ],
        [ 40.  ,  50.  ,  60.  ],
        [  7.  ,   8.  ,   9.  ]],

       [[  1.  ,   2.  ,   3.  ],
        [  0.4 ,   0.5 ,   0.6 ],
        [  0.07,   0.08,   0.09]]])


Zscore in Python and Matlab have different result

here is the code in python

here is the code in python

x = np.array( [ [1, 10, 4], [3, 2, 1], [5, 1, 0] ] , dtype = np.float128 );
x = zscore(x, axis = 0);
print x;

the output is

[[-1.2247449  1.40693  1.3728129]
[ 0.0 -0.57932412 -0.39223227]
[ 1.2247449 -0.82760589 -0.98058068]]

In matlab,

xxx = [1 10 4 ; 3 2 1; 5 1 0]
zscore(xxx)

output is

-1.0000    1.1488    1.1209
0   -0.4730   -0.3203
1.0000   -0.6757   -0.8006

why sciPy.stats.zscore and matlab zscore function are different?