PYTHON equivalents of BITAND and BITSHIFT of MATLAB

2019-05-01 Thread blmadhavan
Hi,

I have the following line from a MATLAB program with FCF (format: UInt_16) as 
input:

ftype = bitand(FCF, 7)
typeBits = bitshift(FCF, -9)
subtype = bitand(typeBits, 7)

I wrote the following in Python for the above commands:

ftype = FCF & 7
typeBits = FCF << -9 --> Is this correct or FCF >> -9?
subtype = typeBits & 7
 
Can someone help me write the equivalent command in PYTHON?

Look forward to your suggestions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PYTHON equivalents of BITAND and BITSHIFT of MATLAB

2019-05-01 Thread blmadhavan
Hello Brian,

Thanks for your suggestion. Which is correct for MATLAB command: typeBits = FCF 
<< -9?

typeBits = FCF >> 9 

or 

typeBits = FCF >> -9

I mean to ask if it should be -9 or +9?

Thanks in advance
Madhavan

On Wednesday, May 1, 2019 at 11:22:10 PM UTC+5:30, Brian Oney wrote:
> On Wed, 2019-05-01 at 10:35 -0700, [email protected] wrote:
> > Hi,
> > 
> > I have the following line from a MATLAB program with FCF (format: UInt_16) 
> > as input:
> > 
> > ftype = bitand(FCF, 7)
> > typeBits = bitshift(FCF, -9)
> > subtype = bitand(typeBits, 7)
> > 
> > I wrote the following in Python for the above commands:
> > 
> > ftype = FCF & 7
> > typeBits = FCF << -9 --> Is this correct or FCF >> -9?
> > subtype = typeBits & 7
> >  
> > Can someone help me write the equivalent command in PYTHON?
> > 
> > Look forward to your suggestions.
> 
> >From the Matlab doc:
> '
> intout = bitshift(A,k)
> intout = bitshift(A,k,assumedtype)
> Description
> 
> example
> 
> intout = bitshift(A,k) returns A shifted to the left by k bits,
> equivalent to multiplying by 2k. Negative values of k correspond to
> shifting bits right or dividing by 2|k| and rounding to the nearest
> integer towards negative infinity. Any overflow bits are truncated. '
> 
> So the equivalent would be:
> 
> >>> typeBits = FCF >> 9
> 
> Cheers
> Brian

-- 
https://mail.python.org/mailman/listinfo/python-list


How to create a boolean mask for the data arrays with uint16, int8 type?

2019-05-06 Thread blmadhavan
Hi,

How can I create a boolean mask for the data arrays with integer type? I want 
to create a 'useSample' boolean array for masking or discarding the unwanted 
data from the array.

[nr,nc] = np.shape(ftype)  # 
useSamples = np.full((nr,nc), True, dtype=bool)

I want to transform the following MATLAB code lines to create the masked array:

useSamples(ftype == 3 & subtype ~=2) = false
useSamples(cad > -70) = false
useSamples(extnQC < 0) = false

Finally, I want to extract X variable samples to exclude/ screen out what I 
don't want (MATLAB expression)

X_screened = X(useSamples)  

Can someone help me how I can transform the above MATLAB lines into Python code?

I have the following data arrays with types uint16 and int8. The 8 columns 
correspond to 8 layers. Number of layers observed is given by 'nlay' variable 
as shown below.

ftype = array([[1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [3, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [3, 1, 1, 1, 1, 1, 1, 1],
   [3, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [3, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [3, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1],
   [1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint16)

subtype = array([[0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [5, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [2, 0, 0, 0, 0, 0, 0, 0],
   [2, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [2, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [2, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0],
   [0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint16)

cad = array([[-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [ -84, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [ -63, -127, -127, -127, -127, -127, -127, -127],
   [ -72, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [ -38, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127],
   [-127, -127, -127, -127, -127, -127, -127, -127]