Checking all the values in a matrix ocaml
up vote
1
down vote
favorite
I have this matrix:
let arr = Array.make_matrix 4 4 0;;
and what to check if all elements are 0.
I heard of the function for_all but I can't quite figure it out how to use it with a matrix, since it expects an int array or a int list.
matrix ocaml
add a comment |
up vote
1
down vote
favorite
I have this matrix:
let arr = Array.make_matrix 4 4 0;;
and what to check if all elements are 0.
I heard of the function for_all but I can't quite figure it out how to use it with a matrix, since it expects an int array or a int list.
matrix ocaml
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have this matrix:
let arr = Array.make_matrix 4 4 0;;
and what to check if all elements are 0.
I heard of the function for_all but I can't quite figure it out how to use it with a matrix, since it expects an int array or a int list.
matrix ocaml
I have this matrix:
let arr = Array.make_matrix 4 4 0;;
and what to check if all elements are 0.
I heard of the function for_all but I can't quite figure it out how to use it with a matrix, since it expects an int array or a int list.
matrix ocaml
matrix ocaml
asked Nov 9 at 20:04
Heitor Hellou
62
62
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
According to the documentation (https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html), here is everything you need to know:
val for_all : ('a -> bool) -> 'a array -> bool
Array.for_all p [|a1; ...; an|]
checks if all elements of the array satisfy the predicate p
. That is, it returns (p a1) && (p a2) && ... && (p an)
.
Example: Array.for_all ((=) 0)
has type int array -> bool
and checks if all elements are zero.
add a comment |
up vote
0
down vote
A matrix is an array of arrays (or an array of rows if you prefer). So you need to execute a for_all
on each one of the rows to check that all elements of the row are zero, and another outer for_all
to check that all the for_all
s over rows are true:
let arr = Array.make_matrix 4 4 0 in
Array.for_all (fun row ->
Array.for_all ((=) 0) row) arr
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
According to the documentation (https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html), here is everything you need to know:
val for_all : ('a -> bool) -> 'a array -> bool
Array.for_all p [|a1; ...; an|]
checks if all elements of the array satisfy the predicate p
. That is, it returns (p a1) && (p a2) && ... && (p an)
.
Example: Array.for_all ((=) 0)
has type int array -> bool
and checks if all elements are zero.
add a comment |
up vote
1
down vote
According to the documentation (https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html), here is everything you need to know:
val for_all : ('a -> bool) -> 'a array -> bool
Array.for_all p [|a1; ...; an|]
checks if all elements of the array satisfy the predicate p
. That is, it returns (p a1) && (p a2) && ... && (p an)
.
Example: Array.for_all ((=) 0)
has type int array -> bool
and checks if all elements are zero.
add a comment |
up vote
1
down vote
up vote
1
down vote
According to the documentation (https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html), here is everything you need to know:
val for_all : ('a -> bool) -> 'a array -> bool
Array.for_all p [|a1; ...; an|]
checks if all elements of the array satisfy the predicate p
. That is, it returns (p a1) && (p a2) && ... && (p an)
.
Example: Array.for_all ((=) 0)
has type int array -> bool
and checks if all elements are zero.
According to the documentation (https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html), here is everything you need to know:
val for_all : ('a -> bool) -> 'a array -> bool
Array.for_all p [|a1; ...; an|]
checks if all elements of the array satisfy the predicate p
. That is, it returns (p a1) && (p a2) && ... && (p an)
.
Example: Array.for_all ((=) 0)
has type int array -> bool
and checks if all elements are zero.
answered Nov 9 at 21:03
de Vilhena
314
314
add a comment |
add a comment |
up vote
0
down vote
A matrix is an array of arrays (or an array of rows if you prefer). So you need to execute a for_all
on each one of the rows to check that all elements of the row are zero, and another outer for_all
to check that all the for_all
s over rows are true:
let arr = Array.make_matrix 4 4 0 in
Array.for_all (fun row ->
Array.for_all ((=) 0) row) arr
add a comment |
up vote
0
down vote
A matrix is an array of arrays (or an array of rows if you prefer). So you need to execute a for_all
on each one of the rows to check that all elements of the row are zero, and another outer for_all
to check that all the for_all
s over rows are true:
let arr = Array.make_matrix 4 4 0 in
Array.for_all (fun row ->
Array.for_all ((=) 0) row) arr
add a comment |
up vote
0
down vote
up vote
0
down vote
A matrix is an array of arrays (or an array of rows if you prefer). So you need to execute a for_all
on each one of the rows to check that all elements of the row are zero, and another outer for_all
to check that all the for_all
s over rows are true:
let arr = Array.make_matrix 4 4 0 in
Array.for_all (fun row ->
Array.for_all ((=) 0) row) arr
A matrix is an array of arrays (or an array of rows if you prefer). So you need to execute a for_all
on each one of the rows to check that all elements of the row are zero, and another outer for_all
to check that all the for_all
s over rows are true:
let arr = Array.make_matrix 4 4 0 in
Array.for_all (fun row ->
Array.for_all ((=) 0) row) arr
answered Nov 10 at 16:50
Anthony Scemama
944715
944715
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232610%2fchecking-all-the-values-in-a-matrix-ocaml%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown