Questions tagged [numpy]

NumPy is one of the many modules in Python that adds support of large multidimensional arrays and matrixes, along with a large library of high-level mathematical functions for operations with these arrays.

Filter by
Sorted by
Tagged with
0 votes
0 answers
12 views

Quantization of an RGB image

I'm doing for a university project a "cartoon-like" filter for an RGB image, so I'm trying to do something to quantize the image. The only libraries I can use are numpy, matplotlib.pyplot ...
perezz's user avatar
  • 1
3 votes
0 answers
41 views

Numpy eig/eigh high memory usage

Let me start with a disclaimer that I am not as experienced in Python as one might want to be, so it could be that this is being caused by something I had caused myself. Disclaimer aside, I've noticed ...
Qubit's user avatar
  • 1,215
0 votes
0 answers
7 views

Widget to visually select time ranges on a graph?

I'm graphing spectral data and I want to be able to graph my data, and using a slider, select portions of the graph and display the times I have selected. Just like highlighting a word in a paragraph, ...
abkeaton's user avatar
0 votes
0 answers
9 views

ArrowInvalid Exception converting numpy array of single string element

ArrowInvalid Exception is raised when converting numpy array of single string element, but works as expected with more than 1 element. Any clue why that is, and how fix (besides the cast workaround ...
overflowed's user avatar
0 votes
1 answer
54 views

Building an (..., N, N) numpy array from a function which returns each (N, N) sub-array

I want to build a numpy array of shape (..., N, N) using a function that returns each (N, N) block. The overall point is to build the (..., N, N) array much faster than by iterating over the first (......
q_mat's user avatar
  • 1
0 votes
1 answer
28 views

Selecting permutationally-unique elements of a symmetric tensor

I have a code which creates a numpy array A of shape (m, m, ..., m) where there are n copies of m. By construction, this array is a symmetric tensor (in the mathematical sense), meaning that A[i, j, .....
Jingyang Wang's user avatar
0 votes
0 answers
21 views

Detecting Acute Angle Lines in a Masked Image using opencv

I'm currently working on a project where I need to identify and extract the region of acute angle lines, resembling a "V" shape, from a given masked image. As shown below and the required ...
mojojojo's user avatar
0 votes
0 answers
9 views

python Runtimeerror doesn't reappear after rerunning a cell

I've been trying to program my own linear regression with gradient descents. While testing different learning rates I encounter with a behavior I consider a bit strange. When I am running a following ...
Zoriana's user avatar
0 votes
0 answers
19 views

How to fix policy loss quick convergence (PPO)?

I am currently working on a RL agent that has to learn how to play pacman. I implemented a PPO algorithm. It worked fine on a small map with only a single pile to eat and one ghost. (The pile was ...
Hamidou's user avatar
  • 75
1 vote
1 answer
79 views

Iterate over rows and update column values based on conditions in Python Pandas DataFrame

I have database for the changes made for given issue Id at any given date . The values in changed_parameter are the parameters for which the changes were made . Its old value and new value for the ...
Shivaraj Math's user avatar
0 votes
0 answers
24 views

Why doesn't numpy support PEP517 builds?

When I run poetry install, I get a ChefBuildError when trying to install numpy=(1.25.1); specifically, it says that Backend 'setuptools.build_meta:legacy' is not available. ModuleNotFoundError: No ...
Brian Nguyen's user avatar
0 votes
1 answer
46 views

How to animate the particles at each timestep instead of their orbits in my simulation?

I want to animate my simulation in a better way: a) Current code is simulating their orbits as a function of time. It is really some zigzag lines at the moment which is "ugly" to look at. b) ...
bluebee09r's user avatar
0 votes
0 answers
27 views

ImportError: cannot import name 'NUMPY' from 'openpyxl.compat.numbers'

Successfully installed openpyxl with no errors When I try to initialize with from openpyxl import Workbook I get the following import error Traceback (most recent call last): File "<pyshell#...
user2320194's user avatar
0 votes
1 answer
33 views

How to pass a list of 2d arguments to Python?

The use case is I have a list of x,y coordinates that I display in a matplotlib graph. I hard coded the values as below to get it to work. The code I was using is: import matplotlib.pyplot as plt ...
James-Jesse Drinkard's user avatar
0 votes
1 answer
36 views

Tensor (5-dim matrix) in python pandas?

I have a CSV file that looks like time Col_A Col_B Col_C Col_D Price 123 A1 B1 C2 D6 23.43 124 A5 B3 C7 D1 14.63 125 A3 B2 C3 D2 343.43 126 A2 B1 C2 D6 43.43 127 A1 B1 C7 D2 6.63 Now I want to ...
Orvar Korvar's user avatar
0 votes
2 answers
40 views

Efficent way to to get values from one pandas dataframe based on a conditon into another pandas dataframe

I have two data sets. One contains 3 ish million proposed work shifts. you can think of the data as resembling this Day Start End Worker ID Store ID Shift ID 12/17/2020 16:00. 22:00 123456. 123 ...
Samuel Crockford's user avatar
0 votes
0 answers
35 views

Removing Rectangular Surfaces in 3D Matplotlib Helical Phase Plot

I am trying to reproduce a 3D plot of a helical phase beam, similar to the image linked here I have implemented the following code using Matplotlib and NumPy: import matplotlib.pyplot as plt import ...
Jean-Felix's user avatar
1 vote
0 answers
27 views

SciPy optimization for FEA truss structure

I am trying to optimize the weight of a truss structure by changing the areas. I have this (shortened/verified code for FEA truss) where x is a array of element areas: stresses = np.zeros(10) def FEA(...
al512's user avatar
  • 45
0 votes
1 answer
37 views

Joining 2 separate excel based 1 condition with python

I have these two frames df1 birthdate ceremony_number 9/30/1895 1st 7/23/1884 1st 3/29/1889 2nd 4/10/1868 3rd 4/8/1892 2nd df2 index dates 1 1929-05-16 2 1930-04-03 3 1930-11-05 I thing is ...
victor_sanger's user avatar
0 votes
0 answers
55 views

Numpy ndArray is not flattening with flatten()

I have a numpy ndArray which is of shape (500,20,8) of float64. Keep in mind however that when I get the shape of such array, I get the following output. I do not know if this is OK: mat = sp.loadmat('...
akaBryan's user avatar
2 votes
0 answers
21 views

Maximum value composite in xarray with dask

I'm trying to perform temporal compositing on multivariate data cubes. The idea, illustrated by the reprex below is for each temporal aggregation (input data have a frequency of 5 days, to be ...
Loïc Dutrieux's user avatar
1 vote
2 answers
83 views

Optimize this python function - apply a linear transformation based on parity of index

I have this simple python function: import numpy as np def fast_transform(img, offset, factor): rep = (img.shape[0]//2, img.shape[1]//2) out = (img.astype(np.float32) - np.tile(offset, rep)) *...
RyArazi's user avatar
  • 353
0 votes
0 answers
34 views

Rotate a 3D cube in a Python Numpy array

I'm trying to create a cube(s) within a 3D array using analytical equation. Here is the code: A = np.zeros((150, 150, 150)) #the array containing the cube r = 15 #cube's edge length, randomly c = (...
hnambui's user avatar
0 votes
0 answers
23 views

does `ndarray.flat.copy()` and `ndarray.flatten()` do the same thing

Currently i have an array arr of which i can get a flat copy of the array with: flat_arr = arr.flat.copy() but this also gives a flat copy of the array: flat_arr = arr.flatten() is there a diffrent ...
Kallinteris Andreas's user avatar
0 votes
0 answers
48 views

SyntaxError: future feature annotations is not defined using python 3.9

I am using python 3.9 in a virtual environment. The only solution I can find just says to use python 3.7 or higher and try using a virtual environment to ensure it is. I am doing both and as you can ...
general's user avatar
  • 963
0 votes
1 answer
43 views

Mapping numpy/scipy function over tensorflow.data.Dataset

I'm trying to extract certain features of a 1D signal that is windowed using tf.keras.preprocessing.timeseries_dataset_from_array, from where I obtain a tf.data.Dataset object, ds (see code below). ...
Paquique's user avatar
0 votes
0 answers
22 views

Getting the Index of the Minimum Value in Selected Rows of Dataframe [duplicate]

I am using the following to return the minimum value in selected rows of a dataframe. It does the job but I cannot work out how to also get the index. How do I do this? local_low = df.loc[i:...
Robsmith's user avatar
  • 383
0 votes
0 answers
39 views

Can sympy arrays be properly sliced after numerical substitutions?

Consider this example for sympy: import numpy from sympy import Array, IndexedBase, symbols k = symbols('k', positive=True) M = IndexedBase('M') M_vals = numpy.array(( (0, 1, 2), (3, 4, 5), ...
HerpDerpington's user avatar
1 vote
2 answers
50 views

How to allocate list of product quantities connected with list of prices to list of customer orders

I have an allocation problem - I have a supply of product at different prices that I need to sell to people at first come first served principle, starting with the cheapest price. I have 4 different ...
barrelquentin997's user avatar
0 votes
0 answers
15 views

convert image to resp(<class 'urllib3.response.HTTPResponse'>) type in Django

previous code : resp = requests.get(IMAGE_API, params={'empid': employee_id}, stream=True).raw return resp resp type is <class 'urllib3.response.HTTPResponse'> now i want to resize this image ...
Shivam Shekhar's user avatar
0 votes
0 answers
27 views

Singular Matrix error when implementing Burgers equation

I'm working on implementing Burger's equation to model the propagation of pressure wave's and I am coming across an error (Singular Matrix error), specifically: 23 J = eval(jac)(x,n,fnon,F,*...
Nexi's user avatar
  • 9
0 votes
1 answer
42 views

FutureWarning: 'DataFrame.swapaxes' is deprecated and will be removed in a future version

Looks like numpy is using deprecated function DataFrame.swapaxes in fromnumeric.py. Anaconda3\lib\site-packages\numpy\core\fromnumeric.py:59: FutureWarning: 'DataFrame.swapaxes' is deprecated and will ...
Aritra Mandal's user avatar
2 votes
0 answers
38 views

Project point cloud into depth image in python

I have a point cloud which is in the same coordinate system as the cameras used for capturing the image. I have a set of points (1000000, 3) The camera extrinsic matrix Rt The camera intrinsic matrix ...
Hannah Stark's user avatar
  • 3,622
1 vote
1 answer
40 views

Filling values in dataframe between 2 specific unique values

i have a following dataframe: index Value 1 None 2 A 3 None 4 A 5 B 6 B 7 None 8 A 9 A 10 B The idea is to fill None in between A and B such that there is no consecutive A or B in the ...
Akav's user avatar
  • 55
1 vote
1 answer
46 views

Detect specific coordinates on video code python

So I'm a beginner in this sphere of coding. I've written some code that uses openCV to detect the edges of my bubble thats being blown out. Video of the bubble The end result outputs many x and y ...
Nikita Zhdanov's user avatar
0 votes
1 answer
63 views

Use case for np.log2 vs math.log2

Sometimes, authors use np.log2 instead of math.log2. For example, in this PyTorch code: num_pools = int(np.log2(spatial)) (where spatial is a Python number) Because math.log2 is a built-in an ...
Richie Bendall's user avatar
0 votes
0 answers
26 views

I'm getting keyerror in python . "Exception has occurred: KeyError 'labels'"

In my python program I'm getting this error: Exception has occurred: KeyError 'labels' KeyError: 'labels' I'm getting error from this code: labels = data['labels'].reshape(-1).astype(np.int32) Can ...
Arghya Chatterjee's user avatar
0 votes
1 answer
72 views

Azure Function - Exception: ImportError: Error importing numpy: you should not try to import numpy from

I'm getting this weird message even thought I already install via Pip Worker failed to function id 2c284181-1e21-4200-b5ea-b7d226696206. [2023-11-30T03:24:02.694Z] Result: Failure [2023-11-30T03:24:02....
Nurdin's user avatar
  • 23.5k
-1 votes
1 answer
79 views

Building an array while looping in Python [closed]

I have a function compute_EOL_Profile that returns an numpy ndarray with 20 elements in it. I want to loop through the 'last dimension' of c0040 and c1000 arrays which has 25 entries/samples for both ...
joeseph's user avatar
0 votes
1 answer
80 views

Saving multiple lists to a file in readable format

In my test particle simulation of 8 planets around the sun, I have pos_output and vel_output python lists. I want to save these to a file and make it readable. These are saving my positions and ...
bluebee09r's user avatar
0 votes
1 answer
80 views

Inconsistencies with calculating mean brightness per pixel of different images

My code gets an image and calculates its mean brightness and standard deviation. When I run the code on a certain data set .TIF which is generally pretty dark and compare the values I get from running ...
Niandra Lades's user avatar
-2 votes
2 answers
50 views

Python (Requests) getting KeyError 'historical'

import requests import pandas as pd import matplotlib.pyplot as plt def stockpriceanalysis(stock): stockprices = requests.get(f"https://financialmodelingprep.com/api/v3/historical-price-full/...
programmer wannabe's user avatar
2 votes
2 answers
154 views

How to make the nested for loop execute faster in python?

Here is my script: for a in range(-100, 101): for b in range(-100, 101): for c in range(-100, 101): for d in range(-100, 101): if abs(2**a*3**b*5**c*7**d-0.3048)...
User's user avatar
  • 25
0 votes
0 answers
61 views

What is causing "int() argument must be a string, a bytes-like object or a number, not '_NoValueType'" with column subset retrieval?

I am using pandas 2.1.3 if that is relevant. My code is as below: data_subset_1 = pd.read_csv("my_path_1") data_subset_2 = pd.read_csv("my_path_2") data_subset_1["subset"...
Layman's user avatar
  • 847
0 votes
0 answers
13 views

Boundary detection from Segmenation file (ascii cr)

I am working on defining the img_segmentation for segments present in different human objects in ascii cr format. I have managed to write the below code so far to detect boundary def load_data(self,...
ParthS007's user avatar
  • 2,631
0 votes
0 answers
25 views

Speed up converting huge 4D arrays to 5D arrays (converting 5D multidimensional image)

I am trying to convert huge 5D HD5 images (read using h5py) into arrays that can be read by Napari. However, I can only extract 3D stacks of it (Z,X,Y) so I have to iterate over channel and time and ...
JohnnyG's user avatar
-4 votes
0 answers
25 views

What are Pickling and Unpickling? [closed]

technical question related to python I require answer of this question Sure, I can help you with that. Python Pickling Tool Python comes with a built-in package called pickle that can be used to ...
Khushi's user avatar
  • 1
1 vote
0 answers
36 views

Why am I able to operate Cupy's NDArray on cuda by using NumPy module?

I was thinking that numpy is used to operate data on cpu, but I found that when I created a cupy.array, I can still use numpy module to operate it, and it's still on cuda. Like this x = cp.array([[1, ...
jieyou zhao's user avatar
0 votes
1 answer
54 views

solve a mathematical expression about a specific unknown parameter with python

I have this equation and want to solve it about t with Python, numpy. First of all I should say that in this equation: <<h r ai hint T*=1000 tau=t/t*>> is known. Before I ask the question ...
Abbas Zandi's user avatar
2 votes
2 answers
32 views

Use matplotlib plot_surface to plot a matrix that contains NaN values

I would like to plot a matrix that contains a combination of float and NaN values. This is a 3D plot where X and Y are the matrix coordinates and Z is the value within the matrix. NaN values should be ...
compilebunny's user avatar

1
2 3 4 5
2263