## How can you find what percentage of a Numpy Array has some value X?

Say I have a numpy array: array = np.array([‘Fe’, ‘Pt’, ‘Ce’, ‘Nd’, ‘Pt’, ‘Fe’, …, ‘Pt’, ‘Ce’, ‘Fe’, ‘Fe’]) Where each entry in the array is either ‘Fe’, ‘Pt’, ‘Ce’, or ‘Nd’. I understand how to …

## Vectorized multiplication: Multiply two vectors in Julia, element-wise

I decided to dive into Julia and hitting the wall; fast. I am trying to replicate a simple operation, which would like as follows in python numpy a = numpy.array([1,2,3]) b = numpy.array([1,2,3]) a*…

## Relate indices where two dataframes are equal with elements in another array

I have an array cluster_true and a dataframe data containing in each row a 2D coordinate. I want to save in another dataframe information regarding how many times for a given 2D coordinate each …

## Numpy: Generating a 2D Sum of Gaussians pdf as an array

I’m trying to generate a [600 x 600] numpy array that contains the sum of 10 Gaussian-like arrays (each with a randomly-generated center). I’ve tried using a Gaussian filter to generate the …

## Create binary array of matching rows in an array using numpy?

I’d like to create a binary array that shows all the matching rows in a numpy array. In this case, down column j of the new matrix, the ith index would correspond to 1 if row i from the original …

## Vectorized version of the following loop in Matlab

What I need to do is, given a vector of labels (numbers 1 through k), construct a matrix Y such that each column is a Boolean vector representing whether or not each the label in Y matches the index …

## generate a 2D array of numpy.random.choice without replacement

I’m tyring to make my code faster by removing some for loops and using arrays. The slowest step right now is the generation of the random lists. context: I have a number of mutations in a chromosome,…

## Vectorizing access to a slice of a three-dimensional matrix in MATLAB

I have a three-dimensional matrix of these sizes, approximately A = rand(20, 1000, 20); where the first and third dimensions are always the same length. I want to zero the elements in a main …

## How to do the following matrix multiplication more efficient in Matlab?

I was wondering if there is any way of doing the following matrix multiplication more efficient, as for example vectorizing it: m=1000;n=500; a=zeros(n,1); b=rand(n,1); A=rand(m,n); B=rand(m,m); for …

## Optimize a numpy ndarray indexing operation

I have a numpy operation that looks like the following: for i in range(i_max): for j in range(j_max): r[i, j, x[i, j], y[i, j]] = c[i, j] where x, y and c have the same shape. Is it …