numpy,computational-geometry,sparse-matrix,kdtree,sparse-array

Following up on Yves' suggestion, here's an answer, which uses scipy's KDTree: from scipy.spatial.kdtree import KDTree import numpy as np def locally_extreme_points(coords, data, neighbourhood, lookfor = 'max', p_norm = 2.): ''' Find local maxima of points in a pointcloud. Ties result in both points passing through the filter. Not to...

numpy,sparse-matrix,sparse,sparse-array

A restriction of scipy.sparse matrices is that they represent linear operators and are thus kept two dimensional, which leads to the question: Which operation are you seeking to do? All einsum operations on a pair of 2D matrices are very easy to write without einsum using dot, transpose and pointwise...

arrays,matlab,matrix,sparse-matrix,sparse-array

You want spdiags: m = 6; %// number of rows n = 10; %// number of columns diags = [-4 -1 0 1 4]; %// diagonals to be filled A = spdiags(ones(min(m,n), numel(diags)), diags, m, n); This gives: >> full(A) ans = 1 1 0 0 1 0 0 0...

matlab,random,sparse-matrix,sparse-array

I assume you want random sampling (without replacement); that is, you want to pick n elements out of matrix A randomly. For that you can apply randsample on the linearized, full version of A: result = randsample(full(A(:)), n); If you want to avoid converting A into full (for example, because...

c++,cuda,gpgpu,thrust,sparse-array

What you have appeared to have overlooked is that copy_if returns an iterator which points to the end of the copied data from the stream compaction operation. So all that is required is this: //copies to device thrust::device_vector<int> d_src = h_src; //Result vector thrust::device_vector<int> d_res(d_src.size()); //Copy non-zero elements from d_src...

optimization,sparse-matrix,julia-lang,sparse,sparse-array

First, you're making term_doc a global variable, which is a big problem for performance. Pass it as an argument, doSparseWay(term_doc::SparseMatrixCSC). (The type annotation at the beginning of your function does not do anything useful.) You want to use an approach similar to the answer by walnuss: function doSparseWay(term_doc::SparseMatrixCSC) I, J,...