Results for numpy

November 30th, 2023

performance improvement on numpy ndarray columnar calculation (row reduction)

I'm doing row reduction on 3 dimensional ndarray (KxMxN), i.e., taking all values of a column and use a reduce function to produce a scalar value; eve...

November 28th, 2023

In Python, why is y**2 sometimes incorrect when y is a numpy array?

First I compute a square in the IDLE shell of Python 3.12.0: >>> x = 123456 >>> x**2 15241383936 This agrees with my TI-89. Now I compute what I woul...

November 27th, 2023

Understanding dtype in NumPy array in Python

I have the following array x: x = np.array([[ 0. , 1. , 0.47351264, 2. ], [ 2. , 3. , 0.65425345, 2. ...

November 24th, 2023

Vectorized Lookup in Dataframe Using Numpy Array

Given a numpy array such as the one below, is it possible to use vectorization to return the associated value in column HHt without using a for loop? ...

November 23rd, 2023

Correctly seeding numpy random generator

For my scientific experiments, I usually seed using: rng = np.random.Generator(np.random.PCG64(seed)) which for the current numpy version is equivalen...

November 23rd, 2023

Efficient way to generate total scores along with numpy.unique()

My task is as follows: Each rows of the labels represents students id who received awards from a certain competition. Each competitions have different...

November 23rd, 2023

How to find a 10x10x3 numpy array within a 1000x1000x3 numpy array (fast)?

I am wondering the following: I have a 10x10x3 and a 1000x1000x3 numpy array. I want to check if the smaller array can be found within the bigger arra...

November 28th, 2023

numpy Polynomial to vector

How do I extract the coefficient vector from a numpy polynomial? In Python, when using the numpy package to construct a polynomial, how do I extract t...

November 20th, 2023

Find first indices of the N largest values of a numpy array without sorting in-place

I need to find first indices of the N largest values of a numpy array without sorting in-place. Examples: 1) Find indices of 2 largest values in an ar...

November 19th, 2023

How to generate a 3-d matrix of coordindates numpy.meshgrid

I need to generate a matrix, say A, and the element of this matrix, say a_{ij}=(x_i,y_j) represents the coordinate of this point. I need the coordinat...

November 16th, 2023

Using numpy arrays with root_scalar() from Python scipy.optimize

I need to solve a differential equation using solve_ivp() which works with numpy arrays. Some of the functions in by model are defined implicitly, so ...

November 15th, 2023

Read Image from numpy and display it: ValueError: conversion from L to PNG not supported

I have a 2D array of an image (slice). The array dimension is (224, 224) and when I read it as an image as shown below, the image mode is shown as "F"...

November 13th, 2023

Julia: Construct an array from an index array and an array to choose from (or: What is the Julia equivalent of np.choose in numpy?)

In Python (Numpy) there is a np.choose function, that constructs an array from an index array and a list of arrays to choose from. Simple example (an...

November 13th, 2023

Is there a way to add a column of numpy random values to a polars dataframe while one column is an input to numpy.random?

Let's say I have a dataframe that has a column named mean that I want to use as an input to a random number generator. Coming from R, this is relative...

November 12th, 2023

why Changing in numpy array change tensor that converted from numpy?

When I convert a numpy array to tensor and change the numpy in differnet ways some change the tensor and some not. it is sample: in this code: array =...

November 13th, 2023

Why numpy.argmax() cannot give correct answer to dict.values() in python?

Data: import numpy as np d = {"a": 10, "b": 11, "c":12} print(d) # This gives {'a': 10, 'b': 11, 'c': 12} Problem: So we try to obtain the index of ...

November 8th, 2023

Compare Elements in One Array with Two Other Arrays by Position in Numpy

I have a numpy array (a_array) and I need to compare each element with the elements in the same position in b_array and c_array, returning the lower o...

November 7th, 2023

Python: How can I handle an error that came up with numpy.loadtxt? TypeError: argument must be an integer

I am writing Python code that takes in a .csv file and uses the data in it to create graphs. I am using numpy.loadtxt to accomplish this. The beginnin...

November 5th, 2023

Numpy power with array as exponent

I have a Python code containing the following lines: # Poisson model lambda_param = 3.0 x_model = numpy.linspace(0, 10, num=11, dtype=int) y_model =...

November 4th, 2023

Sum of numpy array based on elements in another numpy array?

I have 2 arrays: arr1 =np.array([10, 20, 15, 0, 45, 100]) arr2 =np.array([0, 3, 1, 6, 0, 0]) I want to get the sum of those elements from arr1 w...

November 3rd, 2023

prepopulate numpy array with fixed values

How can I prepopulate while initializing numpy array with fixed values? I tried generating list and using that as a fill. >>> c = np.empty(5) >>> c ar...

October 28th, 2023

How to rotate numpy 3D array around its center given a rotation matrix?

I have a 3D numpy array with shape=(50, 50, 50) which I would like to rotate around center, using a rotation matrix R. I am trying to do this by using...

October 28th, 2023

How to append to array in NumPy without flattening the arrays?

How to append two arrays in NumPy without flattening? I tried changing axis. >>> h = np.array([]) >>> g = np.array([2,4]) >>> i = np.array([6,9]) >>> ...

November 2nd, 2023

get float64 for numpy calculation

def chi2_distance(a,b): d=1-(np.dot(a,b)/(norm(a,axis=1)*norm(b))) return d a and b are float32 and have max 8 decimals. but i want...

October 27th, 2023

ufunc created with frompyfunc in numpy python will not work if argument with a default value is omitted

I made a simple function in python and I would like to use it now with numpy arrays. The function has an argument with a default value that can theref...

- 25881
How do I undo the most recent local commits in Git?

- 11618
How can I remove a specific item from an array in JavaScript?

- 20343
How do I delete a Git branch locally and remotely?

- 7387
How can I find all files containing a specific text (string) on Linux?

- 7330
How to find all files containing specific text (string) on Linux?

- 7611
How do I revert a Git repository to a previous commit?

- 2671
How do I create an HTML button that acts like a link?

- 8481
How do I check out a remote Git branch?