Skip to main content

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.

0 votes
1 answer
33 views

Will the NumPy broadcast array ever be created during a binary operation?

I have two numpy.ndarray instances with different shapes. If I add these two arrays, broadcasting will occur between them: import numpy as np x = np.array([1, 2, 3]) y = np.array([[2, 3, 5], ...
dolmok's user avatar
  • 77
1 vote
1 answer
51 views

Calculate distances in a shape with python

I want to calculate the min vertical distance and max horizontal distance of this image. Like the lines. I was trying: _, binary_image = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY) ...
dave qd's user avatar
  • 11
0 votes
0 answers
15 views

num_samples = set(int(i.shape[0]) for i in tree.flatten(data)) IndexError: tuple index out of range (Tensorflow)

When trying to train an Tensorflow LSTM I am getting the following error: File "C:\Users\user\Documents\LSTM_Volatility.py", line 66, in <module> model.fit(x_train , ...
Harry Dunn's user avatar
0 votes
0 answers
38 views

Python: Diagonalize a matrix of very high dimension?

Currently I am working on a problem which involves diagonalizing a matrix to get the eigen values and eigen vector. But now I want to expand the problem to a dimension of 200,000 x 200,000 in size. I ...
Aashish Gautam's user avatar
2 votes
1 answer
64 views

Why do NumPy scalars multiply with custom sequences but not with lists?

I have a question to NumPy experts. Consider a NumPy scalar: c = np.arange(3.0).sum(). If I try to multiply it with a custom sequence like e.g. class S: def __init__(self, lst): self....
Pavlo Bilous's user avatar
2 votes
1 answer
31 views

Lattice-boltzmann simulation runs over the object mask, simulating areas that should be just black

I'm trying to simulate a tesla valve using the method, starting from this code. The problem is that the mask, the boundaries, or the bounce-back are not being applied correctly. If I reverse the ...
yous's user avatar
  • 21
1 vote
2 answers
28 views

sharex and imshow do not produce plots of the same width

Context: I have the x,y and x,z projection of an image. I want the two images to be stacked vertically sharing the same width. My trial: I tried the following: import numpy as np import matplotlib....
Antonio Ragagnin's user avatar
0 votes
1 answer
32 views

Pandas apply is turning matrices into nan/None

I am running the following code on a dataset trying to tally the rows from one data set that match a varied set of criteria. I am using the apply function to store this tally inside of a matrix, where ...
Shand Seiffert's user avatar
0 votes
0 answers
25 views

How to interpolate a 2D Scatter plot in python

I have the following problem: I am working with ultrasonic data from a sector scan. An example is shown in the following: From the file I am reading I receive a 2D array. One dimension is the phase ...
mzr97's user avatar
  • 69
-1 votes
0 answers
34 views

How to solve Process finished with exit code -1073741819 (0xC0000005) in Python? [closed]

I am using Python 3.8 in Pycharm. I have Windows 10 and wanted to reproduce this publicly available code: #!/usr/bin/env python # -*- encoding: utf-8 -*- import sys sys.setrecursionlimit(4000) import ...
Idkwhatywantmed's user avatar
1 vote
1 answer
18 views

Jax vs numpy for generating Heston paths

I have this python code (from QuantPy) which generates stock paths under the Heston model using numpy. I am trying to convert it to using Jax. For some reason, the numpy version runs in about 2 ...
gd1234's user avatar
  • 23
0 votes
1 answer
48 views

How to combine type hint using bound type variable and static types for maximum flexibility?

I would like to add type hints to a simple function. Since it internally only uses numpy calls, it is very flexible with its inputs. Basically, it accepts all array-like objects, for which there is ...
ti-sch's user avatar
  • 1
-2 votes
0 answers
17 views

i am in the process of using pandasai, but keep getting this error from pandas.compat import is_numpy_dev as _is_numpy_dev

from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ i am running numpy version 2 python version 3.11 pandas 1....
user3537234's user avatar
2 votes
2 answers
35 views

Dictionary indexing with Numpy/Jax

I'm writing an interpolation routine and have a dictionary which stores the function values at the fitting points. Ideally, the dictionary keys would be 2D Numpy arrays of the fitting point ...
LordCat's user avatar
  • 482
-4 votes
1 answer
65 views

Python numpy, math: Any way raising a negative number to a decimal power without resulting in Nan?

I am getting errors trying to raise a negative number to a decimal power. For example, I want to calculate this (-2)^(4.8) which should result in valid, real number output (27.85 from my TI-89). I ...
westcoasting__'s user avatar
-3 votes
0 answers
14 views

Deep learning problem for boundary detections [closed]

import numpy as np #Reference: https://stackoverflow.com/questions/55890813/how-to-fix-object-arrays-cannot-be-loaded-when-allow-pickle-false-for-imdb-loa np_load_old = np.load # modify the default ...
Renuka Prasad's user avatar
0 votes
0 answers
24 views

numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject error

I am trying to import pmdarima but it gives the error ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject I uninstalled numpy ...
Eyram's user avatar
  • 1
0 votes
1 answer
45 views

Issue with Custom Rounding Function in Python Pandas

I have implemented a custom rounding function in Python using Pandas, but it's not producing the expected results in certain cases. It basically should always round down to the nearest step.Here's the ...
arrabattapp man's user avatar
-3 votes
0 answers
20 views

how can I compute the striking force of a football player using python [closed]

in a football match between England and Spain Julius Fueke needs a decisive goal, write a Python program that can compute the striking force of each of the players i tried using the import numpy but ...
yagi's user avatar
  • 1
0 votes
0 answers
18 views

How to "average out" multiple curves with sklearn Lasso regression?

The lecture slides here: https://www.cs.cmu.edu/~ggordon/10725-F12/slides/09-acceleration.pdf on page show multiple lines on a convergence plot apparently "averaged out" with Lasso ...
ufghd34's user avatar
  • 151
1 vote
1 answer
60 views

Generate n random 2D points within a valid region

I want to generate a fixed number of random-uniformly distributed xy points within a valid mask. The generated points should be continuous, i.e. can be "between pixels". I'm looking for an ...
Toni's user avatar
  • 33
1 vote
1 answer
24 views

How to extract graph edges in a specific order from networkx?

I am trying to find the shortest path that passes through a set of points that are pretty much aligned. This needs to work in all directions, so I can't just sort them by x or y values. The solution I ...
user19109076's user avatar
1 vote
1 answer
54 views

image to ascii art with edge detection using the sobel filter in python using pygame not rotated correctly

I have to layers of ascii art, one for the sobel filter, one for the general ascii art. I then overlap then and, because the sobel filter is initially only 0, using a simpe filter. The code works for ...
noschXL's user avatar
  • 25
-3 votes
0 answers
30 views

Neural Network cost not changing [closed]

I can't seem to figure out why my cost print function is giving me the same cost every time and my weights and biases are not changing. Help would be greatly appreciated and I have tried putting it ...
Damienwin's user avatar
-1 votes
0 answers
25 views

A problem with Importing Matplotlib (A module that was compiled using NumPy 1.x) [duplicate]

When I'm trying to import matplotlib by the following standard code: import matplotlib.pyplot as plt I'm getting the following error massage: A module that was compiled using NumPy 1.x cannot be run ...
Elad's user avatar
  • 19
3 votes
1 answer
45 views

Why the addion of float32 array and float64 scalar is float32 array in Numpy?

If one add float32 and float64 scalars, the result is float64: float32 is promoted to float64. However, I find that, adding a float32 array and a float64 scalar, the result is a float32 array, rather ...
Ma Ming's user avatar
  • 43
0 votes
0 answers
22 views

Numpy dependency errors while installing the RPM Package

I've created a RPM Package for a python application using setuptools and rpmbuild, the application need few modules like numpy,flask..etc,I've install all the modules in the package itself. but while ...
madduri charan's user avatar
0 votes
0 answers
38 views

A property of Python class returns an empty numpy array with pybind11

I adopted a project that was abandoned by it's original creator on GH: pybind11 bindings for whispercpp. I had to update Python version from 3.8 to 3.11.8 in CI and discovered that some of the test ...
WintermuteAI's user avatar
0 votes
1 answer
41 views

Sobel filter implementation in Pygame is not detecting vertical edges but only horizontal ones

I wanted to apply the Sobel filter to an image for edge detection with the vectors and tried it on some test images, but it only marked the vertical edges despite seeing the horizonal edges. The full ...
noschXL's user avatar
  • 25
0 votes
0 answers
42 views

How can I build my Flutter app to use Python for OpenCV and Numpy? [closed]

I'm developing a Flutter app for iOS that requires image processing using Python, specifically with OpenCV and NumPy. I'm facing several challenges and would appreciate guidance on the best approach: ...
user26409301's user avatar
2 votes
1 answer
39 views

Numpy: Sum N successive array elements, where N comes from a list

Here is code I am trying to optimize: import numpy as np rng = np.random.default_rng() num = np.fromiter((rng.choice([0, 1], size=n, p=[1-qEff, qEff]).sum() for n in num), dtype='...
rad's user avatar
  • 179
1 vote
1 answer
71 views

How do I effectively compute pairwise quantities in numpy?

I want to compute pairwise quantities, e.g. distances between two points. A simple example would be import numpy as np N = 9 x = np.linspace(0,1,N) y = np.abs(x - x[:,None]) # pairwise 1d eucdlidian ...
knods's user avatar
  • 23
0 votes
1 answer
35 views

Unable to install numpy through terminal using pip

I'm trying to install the python package numpy with no luck. I'm using pip install numpy in the terminal, but it returns the following error message: WARNING: Retrying (Retry(total=0, connect=None, ...
asrnpr666's user avatar
1 vote
0 answers
110 views

ModuleNotFoundError: No module named 'numpy._core'

I am trying to load a .npy file created on my local PC with np.save() in google colaboratory. However, when I try to open it on Google Colab with np.load() I get this error: ModuleNotFoundError: No ...
tymerius's user avatar
0 votes
2 answers
68 views

How to transform nested arrays by extending the dimension of the array

Suppose I have an array X with N elements. I would like then to input this array into a 2D array A as follows X=np.array([0,1,2,3],dtype=np.float64) A=np.array([[0,0,X], [0,X,0]],dtype=np....
J.Agusti's user avatar
  • 173
0 votes
1 answer
44 views

What is the meaning of: Pandas data cast to numpy dtype of object. Check input data with np.asarray(data) and how can be solved?

I'm trying to model a time series for a stock price with the following code: import opendatasets as od import numpy as np import pandas as pd import plotly.graph_objects as go from plotly.subplots ...
José's user avatar
  • 201
-2 votes
1 answer
42 views

I'm getting an "src is not a numerical tuple" for an opencv program I'm developing that works in their official documentation but not for me [closed]

I'm creating a python program and trying to get feed from a camera and then perform a fourier transform on it to see its spectrum. I've been trying to initialize the camera with cv2.imread() but for ...
Midkhat Satdanov's user avatar
-2 votes
0 answers
15 views

pyassimp.errors.AssimpError: assimp library not found [closed]

(CGIP) ┏[vbk16] ┖[E:\6th Sem\CG\Mini_Project]> python .\Program.py Traceback (most recent call last): File "E:\6th Sem\CG\Mini_Project\Program.py", line 7, in <module> import ...
VELUPUGONDA BHAVANI KRISHNA's user avatar
0 votes
1 answer
55 views

Efficient stochastic numerical integration over many trajectories

I am implementing a numerical method for solving stochastic differential equations using the Euler-Maruyama method. What I have works, but it is not efficient. The reason is that because of the ...
J.Agusti's user avatar
  • 173
0 votes
0 answers
20 views

read parquet file in dask and convert them to correct numpy shape

I am reading a parquet file in dask and trying to reshape it to how I want it, but it seems rather impossible (I am quite new to dask too). So, I have a parquet file which has some 8M x 384d numpy ...
JohnJ's user avatar
  • 6,996
0 votes
0 answers
36 views

How do I solve the following error message: SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I have been trying to run the following code: import pyaudio import numpy as np from math import pi def make_sinewave(frequency, length, sample_rate=44100): length = int(length * sample_rate) ...
user2115136's user avatar
0 votes
1 answer
43 views

How can I deal with passing 360 degrees when I linearly interpolate between two headings?

A part of my python program linearly interpolates between two compass headings. It works fine as long as I don't have to deal with passing through North. Is there a good way to deal with this rather ...
Phillip Dobbs's user avatar
0 votes
0 answers
38 views

Why print(f"{variable = }") in Python 3.12 also prints numpy type?

I noticed, that with Python 3.12 and a numpy.float64 when I simply do a x = numpy.sqrt(3) # type is <class 'numpy.float64'> now print(f"{x = }") # this is printed >>>x = np....
emefff's user avatar
  • 1
0 votes
1 answer
33 views

Computing and Visualizing Linear Trends in Ocean Temperature Data

I have a dataset containing ocean temperature values for the time period 1950-2022, covering the entire globe. My goal is to calculate the linear trend for each surface grid box and visualize the ...
faeze bh's user avatar
3 votes
2 answers
83 views

How can I get the subarray indicies of a binary array using numpy?

I have an array that looks like this r = np.array([1, 0, 0, 1, 1, 1, 0, 1, 1, 1]) and I want an output of [(0, 0), (3, 5), (7, 9)] right now I am able to accomplish this with the following function ...
John's user avatar
  • 13.5k
1 vote
2 answers
51 views

Why is trapz returning negative values, even when x is sorted ascending and y is all positive?

y = np.array([59817478.73563218, 56195352.29885057, 59679547.70114943, 61071789.08045977, 56678110.91954023, 56900812.06896552, 61942478.73563218, 57360582.18390805, 57423800.57471264, ...
utkala mohanty's user avatar
0 votes
0 answers
15 views

Need help on solving numerical stability issue on hand craft NN use numpy

I try to craft an NN from scratch using Numpy. When I try to run it, the loss goes to the nan value after a few epochs, also the loss increases instead of decreasing. Am I doing something wrong and ...
Nobody The's user avatar
1 vote
1 answer
32 views

How does numpy.polyfit return a slope and y-intercept when its documentation says it returns otherwise?

I have seen examples where slope, yintercept = numpy.polyfit(x,y,1) is used to return slope and y-intercept, but the documentation does not mention "slope" or "intercept" anywhere. ...
user2738698's user avatar
0 votes
0 answers
26 views

PyTorch huge dataset constraints?

I'm training a model in Pytorch to do image-to-image processing. My data is huge, shape is (64152, 3, 5, 2, 64, 144). I'm using memmapping to save on memory as much as humanly possible. The issues ...
Clayton Malott's user avatar
0 votes
0 answers
17 views

Issue with installing wrf-python

i am not able to install wrf-python in linux. it always tells me that numpy module is not found however i have already installed numpy. can anyone help out. tried pip, pipx, sudo, nothing is working. ...
Lalit Deo's user avatar

15 30 50 per page
1
2 3 4 5
2289