Skip to content

Tag: matrix

How to add noise to row/column selection in python

I want to select a specific row/column of a matrix i have, the twist however is that i want an added noise in the selection of the chosen row. Example I have a matrix m of size 100×100. I now want to select row 40 i.e. m[40,:]. What is actually wanted however is not an array with all values of

python iterate over arrays matrices

I am trying to create a new matrix(array) where I have been scouring the documentation in numpy but can’t find a function to satisfy this. Answer You’re looking for numpy.matmul. You’ll need to make the vectors have two dimensions (with a size of one in one of the dimensions). For example:

Compute row distance matrix using only for loops

I am stuck in trying to calculate a distance matrix from different binary arrays and I can only use for loops to resolve this… The problem consists of the following; Imagine I have a binary matrix built with different rows as follows, with dimension n=3,m=3 in this case: And I would like to achieve the …

Reading Matrix from file

I have a txt file consisting some numbers with space and I want to make it as three 4*4 matrixes in python. Each matrix is also divided with two symbols in the text file. The format of the txt file is like this: My code is now like this but it is not showing the output I want. Can you

Multiply two matrices with different dimensions python

Error: ValueError: shapes (3,1) and (3,2) not aligned: 1 (dim 1) != 3 (dim 0) The error occurs because the matrices are different sizes, but how can I multiply two matrices with different size and where the resulting output should be: [-0.78 0.85]? Any help is appreciated! Mathematical question, for better un…

Distance Matrix Haversine

I am working on a data frame that looks like this : I’m trying to make a Haverisne distance matrix. Basically for each zone, I would like to calculate the distance between it and all the others in the dataframe. So there should be only 0s on the diagonal. Here is the Haversine function that I use but I …

Smallest Submatrix in python

It contains an R*C matrix with unique digits. I have to print the submatrix having minimum and maximum integer This is my code: I need a solution without a NumPy array. I found the max and min values and also their index. After that, I don’t know what to do. Answer You can iterate over matrix again and …