Platform
Resources
Pricing
Sign in
Get started
David
I'm a Mechanical Engineer. I do Mechanical Design, Simulation, 3D Printing, Teaching and numerical programming in GNU Octave, Python and JavaScript.
Workspace
Fork
Public
By
David
Edited
Jul 8, 2023
Fork of
Math indexing with an array of booleans
Insert cell
Insert cell
m
=
require
(
"mathjs@11.8"
)
Insert cell
function
isBooleanIndex
(
x
)
{
return
isFlat
(
x
)
&&
m
.
getMatrixDataType
(
x
)
===
"boolean"
;
}
Insert cell
function
isFlat
(
x
)
{
if
(
m
.
isArray
(
x
)
)
{
return
m
.
size
(
x
)
.
length
===
1
;
}
else
if
(
m
.
isMatrix
(
x
)
)
{
return
x
.
_size
.
length
===
1
;
}
else
{
return
false
;
}
}
Insert cell
function
convertBooleanToIndex
(
X
)
{
const
ind
=
[
]
;
X
.
forEach
(
(
x
,
i
)
=>
{
if
(
x
)
ind
.
push
(
i
)
;
}
)
;
return
ind
;
}
Insert cell
function
convertBooleanToIndexMap
(
booleans
)
{
// convert an array of booleans to index
return
booleans
.
map
(
(
_
,
i
)
=>
i
)
.
filter
(
(
_
,
i
)
=>
booleans
[
i
]
)
}
Insert cell
convertBooleanToIndex
(
[
false
]
)
Insert cell
convertBooleanToIndex
(
[
true
,
false
,
true
,
true
,
false
,
true
]
)
Insert cell
convertBooleanToIndexMap
(
[
true
,
false
,
true
,
true
,
false
,
true
]
)
Insert cell
isBooleanIndex
(
[
true
,
false
,
false
]
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
m
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isBooleanIndex
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isFlat
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
convertBooleanToIndex
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
convertBooleanToIndexMap
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML