Category "numpy"

Cosine similarity and cosine distance formulas relation

Can someone explain these two formulas? Do they have any relationship? def _cosine_distance(a, b, data_is_normalized=False): if not data_is_normalized:

Numpy Array is not copying over all values of the array to csv file

I'm having trouble with the formatting of my array when it it saved to a csv file, each time I run the program I get a different result, sometimes the string "c

How to iterate over rows of each column in a dataframe

My current code functions and produces a graph if there is only 1 sensor, i.e. if col2, and col3 are deleted in the example data provided below, leaving one col

np.histogram outputs?? - Python

Trying to understand what kind of output do I get from the histogram function. phase = mod(phase,Nper*2*pi) cl_phase = arange(0,Nper*2*pi+step,step) c,p = histo

Why is not the following 3D polar plot of Array Factor being plotted?

import numpy as np import math as mt import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as axes3d #############################################

How to plot some datasets in pandas based on different thresholds in python

I have a data frame that has 3 columns and I want to plot a line graph based on some thresholds. Here is the data frame date income ratio 0 2022-0

Get two neighboring non-nan values in numpy array

Let's say I have a numpy array my_array = [0.2, 0.3, nan, nan, nan, 0.1, nan, 0.5, nan] For each nan value, I want to extract the two non-nan values to the lef

GCloud compute tunnel always shows warning telling to install numpy

I am setting up a tunnel with gcloud from a remote machine with: gcloud compute start-iap-tunnel ... Everything used to be fine until a few days ago when it st

Polynomial Expansion without sklearn

I want to try and recreate this functions from scratch (without using sklearn): # The matrix is M which is 1000x10 matrix. from sklearn.preprocessing import Po

Filtering out rows in multidimensional numpy arrays

Let's say that I have an array like this: array([[ 1, 2], [-1, -2], [ 0, 0], [-1, 2], [ 2, -1]]) I want to filter out all rows t

How to select 3d array elements with another 3-d array of coordinates?

Let's say I have two array, one with all zero elements and the second one with indices that should be filled with 1. This can be done with the following code: A

Customized search for consequtive values in numpy array

Please assume the following NumPy array: A = array([1, 1, 0, 1, 0, 0, 0, 0, 0, 0]) I would like to find the indices of this array that N consecutive values are

Trying to save image from numpy array with PIL, getting errors

trying to save an inverted image, saved inverted RGB colour data in array pixelArray, then converted this to a numpy array. Not sure what is wrong but any help

Retrieve name of column from its Index in Pandas

I have a pandas dataframe and a numpy array of values of that dataframe. I have the index of a specific column and I already have the row index of an important

Optimized way to implement XOR between floats for huge 2D array data

I need to implement xor between floats in python for huge 2D array data (like thousand row by thousand column matrix). I use the following implementation: impor

Python: Is there any way to get the n-th order antiderivative of a periodic 3D signal/field without padding data?

As stated in the title, I want to obtain the n-th (e.g. 4-th) order antiderivative of a 3D field (e.g. array with shape (1024,1024,1024) ) with period L on each

How does the axis parameter from NumPy work?

Can someone explain exactly what the axis parameter in NumPy does? I am terribly confused. I'm trying to use the function myArray.sum(axis=num) At first I t

Why ais my output "nan", keras model prediction

I'm trying to make an AI attempting to predict numbers from prime number sequence, but my model outputs "[[nan]]". My csv file is formatted like this: number of

NumPy array value error from training in Auto-Keras with StratifiedKFold

Background My sentiment analysis research comes across a variety of datasets. Recently I've encountered one dataset that somehow I just cannot train successfull

How to repair the corrupted image below using opencv, python, numpy and necessary libraries

import cv2 damaged_image = cv2.imread("Corrupted.png") mask = cv2.imread("mask.png", 0) output = cv2.inpaint(damaged_image, mask, 1, cv2.INPAINT_TELEA) cv2.i