Array as index in Python -
i trying utilize array (mask
) has binary values modify array (data
), in order maintain values mask
equal 1
this matlab illustration code:
mask = [0 0 0 1 1 0 0]; info = [1 2 3 4 5 6 7]; data(mask == 0) = []
my result then:
data = [4 5]
what equivalent operation accomplish in python?
you can @ boolean index arrays in numpy
describe.
for example, code in numpy
flavor looks like:
in [38]: import numpy np in [39]: mask = np.array([false, false, false, true, true, false, false]) in [40]: info = np.array([1, 2, 3, 4, 5, 6, 7]) in [41]: data[mask] out[41]: array([4, 5])
in general, if looking create matlab environment in python, should seek utilize numpy
, pandas
, ipython
, matplotlib
together. these first-class libraries replicate matlab ecosystem , in cases give more powerful tools.
python arrays matlab indexing
No comments:
Post a Comment