Good day. If I have the following array: How can I change the array to only show data from user pear? I want to collect all the values from column 1 of user pear. (12, 14) Or alrternatively how can I find the values that are unique in colum 2, e.g. apples, pear and bannana. And then filter by pear

# Tag: numpy

## How to slice and calculate the pearson correlation coefficient between one big and small array with “overlapping” windows arrays

Suppose I have two very simple arrays with numpy: I would like to find which slice of array reference has the highest pearson’s correlation coefficient with array probe. To do that, I would like to slice the array reference using some sort of sub-arrays that are overlapped in a for loop, which means I shift one element at a time

## How to create a tensor from a list of matrices in numpy?

How do I create a tensor T that is 3x2x3; as in, T[:,:,0] = A, T[:,:,1] = B, and T[:,:,2] = C? Also I may not know the number of matrices that I may be given before run time, so I cannot explicitly create an empty tensor before hand and fill it. I tried, but that gives me an array

## Appending 1D Ndarray to 2D Ndarray

I’m attempting to append a 1D array which have generated by appending elements one at a time to a 2D array as a new row in the array. I’m pretty lost as to why this code doesn’t work? They are both arrays of 5 elements, but get the following error? “ValueError: all the input arrays must have same number of

## Matrix row masking at different indices

I have an 2-D array that I want to find the max value per row and then find the next max-value that is not within +/- n of the previous value. For example I have the following matrix: Now I’d like to get the next max value not within say +/- 2 of the current max. Here is what I

## Transform a 3D numpy array to 1D based on column value

Maybe this is a very simple task, but I have a numpy.ndarray with shape (1988,3). I want to create a 1D array with shape=(1988,) that will have values corresponding to the column of my 3D array that has a value of 1. For example, How can I do this? Answer You can use numpy.nonzero: Output: array([0, 1, 2, 1, 0,

## How to calculate the expectation value for a given probability distribution

I am writing a program to determine the expectation value, expectation of the X^2 and E(X – X_avg)^2. I have written a program like so: The dataset that I am using is: Expected: E(X) = 16 E(X^2) = 276 E(X- X_avg)^2 =20 Actual: Answer Your problem is the step 1, so I took the liberty of rewriting it: df: The

## Group two(2) or more categorical data by week(7days) in pandas python

This is how my data looks like: I want to aggregate this by category, Issue and Date(weekly) to get count of record. Date: Group, the result should be monday to sunday Count: ADD, if two or more records have same Name and fall in a same week Date time (if falls on same interval 7 days week) The desired output

## how to calculate the distances between all datapoints among each other

I want to check which data points within X are close to each other and which are far. by calculating the distances between each other without getting to zero, is it possible? Answer Using just numpy you can either do, or,

## Geometric series: calculate quotient and number of elements from sum and first & last element

Creating evenly spaced numbers on a log scale (a geometric progression) can easily be done for a given base and number of elements if the starting and final values of the sequence are known, e.g., with numpy.logspace and numpy.geomspace. Now assume I want to define the geometric progression the other way around, i.e., based on the properties of the resulting