Checking if a matrix contains only zeros
10-07-2023, 12:59 PM
Post: #1
 komame Member Posts: 238 Joined: Aug 2015
Checking if a matrix contains only zeros
What is the simplest method to check if a matrix contains only zeros? If there's a method specifically for square matrices, I'm interested in that as well, but a solution for matrices of any dimensions would be more useful.

Piotr
10-07-2023, 01:54 PM
Post: #2
 Didier Lachieze Senior Member Posts: 1,618 Joined: Dec 2013
RE: Checking if a matrix contains only zeros
ROWNORM or COLNORM will return 0 if there is only zeros in the matrix.
10-07-2023, 04:15 PM
Post: #3
 Valentin Albillo Senior Member Posts: 1,081 Joined: Feb 2015
RE: Checking if a matrix contains only zeros
(10-07-2023 01:54 PM)Didier Lachieze Wrote:  ROWNORM or COLNORM will return 0 if there is only zeros in the matrix.

ABS applied to a matrix will also return 0 only if the matrix is all zeros.

It actually computes the Frobenius norm so it might be slightly slower than the norms you mention, but it looks much cleaner and understandable in the source code.

V.

All My Articles & other Materials here:  Valentin Albillo's HP Collection

10-07-2023, 06:59 PM
Post: #4
 komame Member Posts: 238 Joined: Aug 2015
RE: Checking if a matrix contains only zeros
(10-07-2023 01:54 PM)Didier Lachieze Wrote:  ROWNORM or COLNORM will return 0 if there is only zeros in the matrix.

(10-07-2023 04:15 PM)Valentin Albillo Wrote:  ABS applied to a matrix will also return 0 only if the matrix is all zeros.

Didier, Valentin,
Thank you for both answers. Both provide exactly what I was looking for.
 « Next Oldest | Next Newest »