Category "numpy-ndarray"

how to calculate Manhattan distance (or L1/ cityblock) for two 2D array?

For 1D vector/array it's easier. For example: array1 = [1, 2, 3] array2 = [1, 1, 1] manhattan distance will be: (0+1+2) which is 3 import numpy as np def city

Python: appending numpy.array to list python overwrites the previous elements

I'm trying to plot a stellar orbit in a given potential. First, I initialize the position and velocity, and derive the acceleration from the position according

Efficiently get first N numbers that satisfy a condition in each row in a pytorch/numpy tensor

Given a tensor b, and I would like to extract N elements in each row that satisfy a specific condition. For example, suppose a is a matrix that indicates whethe

Is there something like np.linspace for 3D lines?

I have a 3x1 point vector representing the start point of some line, and a 3x1 point vector representing the end of some line. I would like to sample an arbitra

How to save a 'pos dictionary' type of object? (NetworkX)

I am using the networkx as nx. After creating a graph object (G), I use the data = nx.spring_layout(G) method to generate a dictionary (pos). Generating this po

How to add a new array to an existing npz file in a standard way?

I have a function which writes an array to a compressed *.npz file: def save_a(file): np.savez_compressed(file, a=[[1, 2, 3]]) I want to make a function

Convert n same-size, d-dimensional numpy arrays to a dataframe with d+n columns

I recently asked this question, about converting n 2-dimensional arrays to a dataframe with 2+n columns. The solution I got works perfectly well, but can not ea

How can I convert boolean values from np.diff() to the actual values

I have a numpy array of np.shape=(n,) I am attempting to iterate through each value of the array and subtract the 2nd value from the 1st, then see if the differ