Is there a NumPy-like package for Node.js and if not why not? [closed]

No, there are no technical reasons why a numpy-like package does not exist for Node.js and, more generally, JavaScript. There are two main obstacles preventing Node.js and JavaScript from achieving more mind share in the data science and numeric computing communities. The first obstacle is community. While the JavaScript community is huge, the subset of … Read more

How to calculate a Fourier series in Numpy?

In the end, the most simple thing (calculating the coefficient with a riemann sum) was the most portable/efficient/robust way to solve my problem: import numpy as np def cn(n): c = y*np.exp(-1j*2*n*np.pi*time/period) return c.sum()/c.size def f(x, Nh): f = np.array([2*cn(i)*np.exp(1j*2*i*np.pi*x/period) for i in range(1,Nh+1)]) return f.sum() y2 = np.array([f(t,50).real for t in time]) plot(time, y) … Read more

Safer way to expose a C-allocated memory buffer using numpy/ctypes?

You have to keep a reference to your Wrapper while any numpy array exists. Easiest way to achieve this, is to save this reference in a attribute of the ctype-buffer: class MyWrapper(object): def __init__(self, n=10): # buffer allocated by external library self.size = n self.addr = libc.malloc(C.sizeof(C.c_int) * n) def __del__(self): # buffer freed by … Read more

Weird indexing using numpy

This is how numpy uses advanced indexing to broadcast array shapes. When you pass a 0 for the first index, and y for the last index, numpy will broadcast the 0 to be the same shape as y. The following equivalence holds: x[0,:,:,y] == x[(0, 0, 0),:,:,y]. here is an example import numpy as np … Read more

How can I convert a two column array to a matrix with counts of occurences?

One way could be to build a graph using NetworkX and obtain the adjacency matrix directly as a dataframe with nx.to_pandas_adjacency. To account for the co-occurrences of the edges in the graph, we can create a nx.MultiGraph, which allows for multiple edges connecting the same pair of nodes: import networkx as nx G = nx.from_edgelist(pair_array, … Read more

Specific type annotation for NumPy ndarray using mypy

What you are looking for is the numpy.typing.NDArray class: https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NDArray numpy.typing.NDArray[A] is an alias for numpy.ndarray[Any, numpy.dtype[A]]: import numpy as np import numpy.typing as npt a: npt.NDArray[np.complex64] = np.zeros((3, 3), dtype=np.complex64) # reveal_type(a) # -> numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[numpy.typing._32Bit, numpy.typing._32Bit]]] print(a) prints [[0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j]] Note that even though you annotate … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)