Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h2>Import modules</h2>
</p>

<hr />
<h2>Basic Numpy Arrays</h2>
<h2>Basic NumPy arrays</h2>

<p>
<input type="button" class="btn btn-success" value="np" onclick="np()" />
Expand Down Expand Up @@ -58,7 +58,7 @@ <h2>Basic Numpy Arrays</h2>
</p>

<hr />
<h2>Array Types</h2>
<h2>Array types</h2>

<p>
<input type="button" class="btn btn-success" value="dtype" onclick="dtype()" />
Expand All @@ -67,6 +67,16 @@ <h2>Array Types</h2>
<input type="button" class="btn btn-success" value="int" onclick="dtype(this.value)" />
</p>

<hr />
<h2>Dimensions and shapes</h2>

<p>
<input type="button" class="btn btn-data" value="memory size" onclick="memorySize();" />
<input type="button" class="btn btn-data" value="ndim" onclick="dimensionShape(this.value);" />
<input type="button" class="btn btn-data" value="shape" onclick="dimensionShape(this.value);" />
<input type="button" class="btn btn-data" value="size" onclick="dimensionShape(this.value);" />
</p>

</div>
</td>
<td id="textbox">
Expand Down
21 changes: 19 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// basic NumPy arrays
// Basic NumPy arrays
let array = document.getElementById("array");
let variable = document.getElementById("variable");
let index = document.getElementById("index");
Expand Down Expand Up @@ -55,7 +55,7 @@ const range = () => {
}
}

// Array Types
// Array types
const dtype = (type) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
Expand All @@ -67,3 +67,20 @@ const dtype = (type) => {
document.editor.textbox.value+= "\n" + variable.value + " = np.array([" + array.value + "], dtype=np." + type + ")";
}
}

// Dimensions and shapes
const dimensionShape = (arg) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
} else {
document.editor.textbox.value+="\n" + variable.value + "." + arg;
}
}

const memorySize = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
} else {
document.editor.textbox.value+="\nprint('%d bytes' % (" + variable.value + ".size * " + variable.value + ".itemsize))";
}
}
8 changes: 8 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ td {
border-color: #398439;
}

.btn-data {
background: #646464;
}

.btn-success, .btn-data {
color: white;
}

/* input */

input {
Expand Down