xxxxxxxxxx
// install puppeteer + typescript
npm install puppeteer
npm install -D ts-node typescript @types/puppeteer
// index.ts
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await browser.close();
})();
// run it
npx ts-node index.ts
xxxxxxxxxx
In [140]: np.diag(np.full(5,-2))
Out[140]:
array([[-2, 0, 0, 0, 0],
[ 0, -2, 0, 0, 0],
[ 0, 0, -2, 0, 0],
[ 0, 0, 0, -2, 0],
[ 0, 0, 0, 0, -2]])
In [141]: np.diag(np.ones(4),1)
Out[141]:
array([[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.],
[0., 0., 0., 0., 0.]])
In [142]: np.diag(np.full(5,-2))+np.diag(np.ones(4),1)+np.diag(np.ones(4),-1)
Out[142]:
array([[-2., 1., 0., 0., 0.],
[ 1., -2., 1., 0., 0.],
[ 0., 1., -2., 1., 0.],
[ 0., 0., 1., -2., 1.],
[ 0., 0., 0., 1., -2.]])
This code uses only numpy instead of numpy and scipy
Create a diagonal 5x5 Matrix with -2
xxxxxxxxxx
In [140]: np.diag(np.full(5,-2))
Out[140]:
array([[-2, 0, 0, 0, 0],
[ 0, -2, 0, 0, 0],
[ 0, 0, -2, 0, 0],
[ 0, 0, 0, -2, 0],
[ 0, 0, 0, 0, -2]])
In [141]: np.diag(np.ones(4),1)
Out[141]:
array([[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.],
[0., 0., 0., 0., 0.]])
In [142]: np.diag(np.full(5,-2))+np.diag(np.ones(4),1)+np.diag(np.ones(4),-1)
Out[142]:
array([[-2., 1., 0., 0., 0.],
[ 1., -2., 1., 0., 0.],
[ 0., 1., -2., 1., 0.],
[ 0., 0., 1., -2., 1.],
[ 0., 0., 0., 1., -2.]])