All Questions
1,251 questions
0
votes
1
answer
50
views
numpy.cov() Giving Incorrect Answer
I'm trying to use Python and NumPy to calculate a covariance matrix.
Here is the matrix:
[[0.69, 0.49],
[-1.31, -1.21],
[0.39, 0.99],
[0.09, 0.29],
[1.29, 1.09],
[0.49, 0.79],
[0.19, -0.31],
[-...
0
votes
1
answer
29
views
Python - How do I automate the creation of row and column headers (in line with a table's dimension)?
How do I automate the creation of row and column headers?
I would like to randomly generate a matrix, and then add row and column headers aligned with the indices, i.e. R1, R2, R3… for the rows and C1,...
2
votes
2
answers
96
views
Apply function for lower triangle of 2-d array
I have an array:
U = np.array([3, 5, 7, 9, 11])
I want to get a result like:
result = np.array([
[ np.nan, np.nan, np.nan, np.nan, np.nan],
[U[0] - U[1], np.nan, np....
3
votes
1
answer
58
views
Numpy array does not correctly update in Gaussian elimination program
I am trying to write a function gaussian_elim which takes in an n x n numpy array A and an n x 1 numpy array b and performs Gaussian elimination on the augmented matrix [A|b]. It should return an n x (...
-3
votes
1
answer
48
views
Concatenate a few row vectors into a matrix
Four 1X3 row vectors, trying to concatenate them into a 4X3 martrix. Here is my code that is not working:
ul = np.array([-320, 240, 1])
ur = np.array([320, 240, 1])
br = np.array([320, -240, 1]...
0
votes
1
answer
58
views
numpy giving wrong matrix results?
I am doing some matrix calculations and I am getting some wrong values.
import numpy as np
np.set_printoptions(formatter={'float': lambda x: "{0:0.2f}".format(x)})
#deltaT
arr1 = np.array([[...
1
vote
2
answers
77
views
How can I set a specific value on an array (matrix) of booleans per True/False without using loops in python?
I am trying to make two random generated matrices mat1 and mat2 with random integer values between 0, 255 and check which cells are equal.
and I know this much
import numpy as np
mat1 = np.random....
0
votes
1
answer
151
views
How to Generate a Random Complex Symmetric Unitary Matrix in Python?
I am trying to optimize a complex symmetric unitary matrix
𝐴 with dimensions N*N using Python.
First of all, how to generate matrix 𝐴 that should satisfies the two conditions:
𝐴=𝐴^{T} (...
1
vote
1
answer
111
views
algorithm to detect pools of 0s in a matrix
I'm writing an algorithm that detects regions of contiguous empty cells that are completely surrounded (orthogonally) by filled cells and do not extend to the edge of the grid. Let's call such regions ...
0
votes
0
answers
50
views
Raising a Numpy Array to a large power [duplicate]
I am using Numpy to raise a 2 X 2 array (matrix), with positive elements, to an integer power. But if I use a high enough power, I get negative values in the result:
A = np.array([[1, 1], [1, 0]])
B = ...
0
votes
1
answer
42
views
How to reorder rows of a numpy array according to another array [duplicate]
I have a matrix A whose rows have to be reordered or shuffled according to the sequence in array b. The actual size of a Matrix A is more than 100 rows. The suggested answer need to be scalable.
A = ...
0
votes
2
answers
156
views
How to reproduce `kneighbors_graph(include_self=True)` using `KNeighborsTransformer` in sklearn?
My ultimate goal is replace some methods that use kneighbors_graph with transformers from the sklearn-ann package. All the methods in sklearn-ann are implemented as sklearn-compatible transformer ...
0
votes
1
answer
42
views
Update a Column of a Matrix where each MongoDB document is a Row
I'm storing matrices in MongoDB where each document is a row of values. Example of two small matrices but assume there are thousands of rows and columns:
[
{ matrix_id: 123, row_id: 0, values: [1, 2,...
0
votes
1
answer
99
views
How to fix : TypeError: 'numpy.ndarray' object is not callable
I'm currently working on implementing a Newton-Raphson algorithm to solve a statistical problem. However, I'm encountering an issue with matrix multiplication that is resulting in the following error: ...
0
votes
3
answers
80
views
How to (idiomatically) read indexed arrays from a delimited text file?
I have text files from an external source that are formatted like so:
0 0 -0.105961 0.00000
1 0 -1.06965 0.00000
1 1 -0.0187213 -0.240237
...