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.
numpy
114,448
questions
1
vote
2
answers
28
views
Numpy where using multi-dimensional arrays
I have an array of length N of 2x2 arrays, and an array of N Booleans corresponding to good 2x2 arrays. I want to replace the bad 2x2s with np.zeros((2,2)).
I tried np.where but it failed. Here's an ...
1
vote
1
answer
41
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],
...
2
votes
2
answers
82
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)
...
0
votes
0
answers
44
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 ...
2
votes
1
answer
79
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....
1
vote
2
answers
35
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....
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 ...
0
votes
0
answers
28
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 ...
-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 ...
1
vote
1
answer
21
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 ...
0
votes
1
answer
51
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 ...
-2
votes
0
answers
18
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....
2
votes
2
answers
41
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 ...
-4
votes
1
answer
67
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 ...
-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 ...