Message Boards Message Boards

0
|
4600 Views
|
9 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Matrix operation - how to eliminate elements (rows) in a Matrix

Posted 5 years ago

Hi

I have a 2D matrix, and I like to eliminate rows whose last column elements are zeros. Anyone could give me a quick hand (or a function)?

Xiaxing (a Mathematica beginner)

POSTED BY: Xiaxing Xiong
9 Replies
Posted 5 years ago

Hi Xiaxing,

Is there a reason for using Graphics? Example using ListPlot.

points = {{1, 1}, {2, 2}, {3, 3}, {3, 4}} // Map[List];
pointSizes = {1.1, 3.2, 2, 4};
ListPlot[points, PlotStyle -> PointSize /@ (pointSizes/100)]

enter image description here

Since this question is unrelated to the original question, it should have been a new post.

POSTED BY: Rohit Namjoshi
Posted 5 years ago

Hi Again

I like to plot a hundreds of points with different sizes: example points locations pts= {{1,1},{2,2},{3,3}, {3,4},....}, with sizes ptsize={1.1, 3.2, 2, 4, ...} I'm try to use: Graphics[{Black, PointSize[#], Point[pts]]

How should I do with the PointSize? Any quick helps?

Great thanks

Xiaxing (a Mathematica beginner)

POSTED BY: Xiaxing Xiong
Posted 5 years ago

If I like to turn {{a, b, c, d, e}, {2, 3, 1, 2, 3}}

into {{a, a, b,b,b, c, d,d,e, e,e},

Meaning repeat the number of elements per numbers in the 2nd row.

Any quick helps?

Xiaxing (a Mathematica beginner) Great thanks.

POSTED BY: Xiaxing Xiong
Posted 5 years ago

Also if Matrix {{a,b,c,d,e},{2,3,1,2,3}} needs to turn to {{a,a,b,b,b,c,d,d,e,e,e}}
meaning to repeat the elements the number of the 2nd row indicate.

Anyone can give me a quick help?

Thanks

Xiaxing (a Mathematica beginner)

POSTED BY: Xiaxing Xiong
Posted 5 years ago

Not too hard:

Flatten[MapThread[ConstantArray, {{a, b, c, d, e}, {2, 3, 1, 2, 3}}]]
   {a, a, b, b, b, c, d, d, e, e, e}
POSTED BY: J. M.
Posted 5 years ago

It worked perfectly. Thanks

POSTED BY: Xiaxing Xiong
Posted 5 years ago

Hi Xiaxing,

Maybe this?

SeedRandom[12];
matrix = RandomInteger[2, {5, 5}]
(* {{0, 2, 1, 0, 0}, {0, 2, 2, 2, 0}, {1, 2, 1, 1, 0}, {0, 1, 2, 2, 2}, {1, 0, 0, 2, 1}} *)

matrix // Select[Last@# != 0 &]
(* {{0, 1, 2, 2, 2}, {1, 0, 0, 2, 1}} *)
POSTED BY: Rohit Namjoshi
Posted 5 years ago

It worked. Great thanks

Xiaxing

POSTED BY: Xiaxing Xiong
Posted 2 years ago

Hi Rohit and others What about when one wants to use three 2 X 2 matrices in the computation as inputs to get three 3 X 3 matrices as output ? I am expecting as one of the output a 3 X 3 matrix {{0, 0, 0}, {0, 2, 0}, {0, 0, -2}} . The computation is correct, however, to achieve the 3 X 3 is challenging. See attachment.

Attachments:
POSTED BY: Nomsa Ledwaba
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract