Reputation: 333
I have a 2D matrix C
in Python and I am trying to do what is done in MATLAB.
MATLAB code:
Tr = 5;
Td = 4;
Gr = 4;
Gd = 1;
C(union(1:(Tr+Gr),end-(Tr+Gr-1):end), :) = 0;
C(:, union(1:(Td+Gd),end-(Td+Gd-1):end)) = 0;
Python code:
ru1 = C[:Tr+Gr]
a = np.shape(C)
ru2 = C[a[0] - (Tr + Gr -1):]
C[ru1.union(ru2),:]= 0
However, I am getting an error on union
. How can I take the union of these arrays?
Upvotes: 0
Views: 76
Reputation: 35525
Try numpy.union1d
. union()
only works on sets ( defined with {}
)
Upvotes: 1