Flatten a Matrix
10-09-2014, 03:04 AM
Post: #1
 dalupus Junior Member Posts: 41 Joined: Oct 2014
Flatten a Matrix
Hi Guys,

First I was looking for some kind of function that would tell me if my matrix had any 0's but couldn't find anything.

So I decided to just make a contains function but I wanted to make it work for lists,vectors and matrices but I couldn't find any way to flatten a matrix or turn it into a list.

Any suggestions?

Also as a side question is there a set of basic functions like this out there that someone has maybe put together so we don't all have to reinvent the wheel?

Thanks,
Mike
10-09-2014, 04:05 AM
Post: #2
 Joe Horn Senior Member Posts: 1,591 Joined: Dec 2013
RE: Flatten a Matrix
(10-09-2014 03:04 AM)dalupus Wrote:  First I was looking for some kind of function that would tell me if my matrix had any 0's but couldn't find anything.

So I decided to just make a contains function but I wanted to make it work for lists,vectors and matrices but I couldn't find any way to flatten a matrix or turn it into a list.

Any suggestions?

mat2list([[1,2],[3,4]]) --> {1,2,3,4}.
Therefore, ΠLIST(mat2list(matrix)) returns 0 if any matrix elements are zero.

<0|ɸ|0>
-Joe-
10-09-2014, 12:49 PM
Post: #3
 DrD Senior Member Posts: 1,117 Joined: Feb 2014
RE: Flatten a Matrix
I wonder why "Flatten a Matrix" doesn't flatten a -list- of matrices flatter?

example:

a:=([1,2],[3,4])
b:=([5,6],[0,1])

mat2list(a) => {1,2,3,4} and mat2list(b) => {5,6,0,1} Good!

mat2list(a,b) also mat2list({a,b}) also mat2list([a,b]) => {{[1,2],[3,4]},{{[5,6],[0,1]}}

The above takes on 'flattening' a list of matrices fed to the mat2list function each yield a list of matrices, instead of their collective elements. Would it not be more consistent to have the function return "the elements" for the collection of input matrices, as the user guide suggests?

Like this do-si-do does: mat2list(concat(a,b)) => {1,2,5,6,3,4,0,1}
-or- perhaps even better => {1,2,3,4,5,6,0,1}

-Dale-
10-09-2014, 02:17 PM
Post: #4
 dalupus Junior Member Posts: 41 Joined: Oct 2014
RE: Flatten a Matrix
Thanks that is what I was looking for.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)