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,582
questions
0
votes
1
answer
31
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],
...
7
votes
4
answers
43k
views
meaning of comma operator in python
I understood simple concepts about comma operator in python. For instance,
x0, sigma = 0, 0.1
means x0=0, and sigma=0.1. But I obtained a code that has a line that looks like the following.
y, xe =...
4
votes
3
answers
1k
views
Passing an array to numpy.dot() in Python implementation of Perceptron Learning Model
I'm trying to put together a Python implementation of a single-layer Perceptron classifier. I've found the example in Sebastian Raschka's book 'Python Machine Learning' very useful, but I have a ...
1
vote
1
answer
50
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)
...
2
votes
1
answer
605
views
Plotting with Python
I have a .txt file from which I find ordered pairs, and then draw a graphic using numpy and matplotlib. For example these are my ordered pairs:
[[(4.0, 0), (0, 6.0)], [(6.0, 0), (0, 3.0)]]
(Each sub-...
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 ...
1
vote
2
answers
27
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....
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 ...
0
votes
1
answer
12k
views
Gauss-Jordan Elimination in python
I am working on code to do Gauss-Jordan elimination in python. My directions are as follows:
def gauss_jordan(A):
for each row k do
i* <- argmax_{k<i<n} |A_{ik}|
if A_{i*k} = 0 then
...
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 , ...
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....
498
votes
10
answers
361k
views
What is the purpose of meshgrid in NumPy?
What is the purpose of np.meshgrid? I know it creates some kind of grid of coordinates for plotting, but I can't see the direct benefit of it.
The official documentation gives the following example, ...
4
votes
3
answers
2k
views
Numpy parse to ndarray from string
I have stringified ndarray passed from server to the client-side, the example of that array could be seen below
import numpy as np
str_array = "[[0.1233 0.333 4.1111] [0.1233 0.333 4.1111] [0.1233 0....
2
votes
2
answers
1k
views
Numpy: Meshgrid vs ix_
From the look of it, both numpy.meshgrid and numpy.ix_ seem to do pretty much the same. Is there a significant difference between them, or is the other just a convenient shortcut?
46
votes
4
answers
24k
views
Mypy/typeshed stubs for Pandas
Just checking to see if anybody listening has already generated a sort-of-working set of mypy/typeshed stubs for `pandas`. I naively ran stubgen over the local pandas install which generated some ...