1

I do know a bit of Python, am however new to Pyodide and have no experience in Javascript. I am looking for an easy way to display results in the browser:

%% md
a + b = HERE_I_WANT_TO_DISPLAY_THE_RESULT

%% py
import numpy as np
a = np.array([[1],[2]])
b = np.array([1],[2],[3])
result = a+b

Following this Pyodide demo https://alpha.iodide.io/notebooks/300/ I think it might have something do with how to print matrices in javascript?

K1K1
  • 19
  • 5

2 Answers2

1

Try removing result = in the last line of your code. I believe Iodide evals the code you give it and prints out the result.

%% py
import numpy as np
a = np.array([[1],[2]])
b = np.array([[2],[3]])
a+b
Maurice Lam
  • 1,577
  • 9
  • 14
0

You can also import the window.document object and access all of its interfaces. For example, this allows us to manipulate the DOM.

This example show how to insert a div into the body

%% py

from js import document

div = document.createElement('div')
div.innerHTML = '<h1>This element was created from Python</h1>'
#insert into body as a first child
document.body.prepend(div)

The Iodide project is no longer under development, but you can use its Pyodide sub-project. Check out my tutorial on it.

Aray Karjauv
  • 2,679
  • 2
  • 26
  • 44