In Julia, I would like to generate a matrix with exactly one nonzero entry in each row and column, where each of these nonzero entries has modulus one. Is there any way to this in Julia?
Randomly generate signed permutation matrix in Julia?
112 views Asked by James Rider At
2
There are 2 answers
0
AboAmmar
On
You can simply shuffle row indices and place (1,-1) randomly in each column based on the shuffled row index.
function bipolar(siz)
m = n = siz
A = zeros(Int,m,n)
rowind = shuffle(1:m)
for (j,i) in enumerate(rowind)
A[i,j] = rand((-1,1))
end
A
end
Example run:
bipolar(5)
5×5 Matrix{Int64}:
0 0 1 0 0
0 0 0 0 1
0 0 0 -1 0
1 0 0 0 0
0 1 0 0 0
Related Questions in MATRIX
- Setting diagonal of a matrix to zero
- CUDA matrix inversion
- Function to create matrix of zeros and ones, with a certain density of ones
- DirectX 9 With No SDK Installed - How To Translate a D3DMATRIX?
- Using the sympy module to compute the matrix multiplication involving symbols
- Rendering a visualisation of matrix using pygame
- I do not receive iOS push notifications from Element Matrix Notify
- Matrix reconstruction by SVD in tensorflow
- Why does the following code detect this matrix as a non-singular matrix?
- Bound for product of matrices
- iterating through raster bands to perform calculation
- How to make a heatmap and the matrix for it?
- MATLAB: Turn every element of complex matrix into another matrix
- Matrix calculated based on the previous value
- Matlab array of structure
Related Questions in JULIA
- Getting updates from SDE solver in Julia
- Why am I getting MethodErrors when using continuous callback in Julia ODE solver?
- Using tickformat in a Makie.jl colorbar
- Julia - Second-order ODE gives wrong results
- Integrals of multiple variables with some of the limits depending on variables (Julia)
- julia Jupyter on() interaction error message
- Overlaying contour lines for a specific value
- Trouble with passing data from DataLoader to Learner in FluxTraining.jl for UNet model
- Is there a ´right´ way to get CSFML.jl in Julia to work on MacOS?
- Build Python executable with Julia dependencies
- Rust performance vs Julia
- PlotlyJS.jl LaTeX integration in VS Code
- Julia syntax error @kwdef with default value as string
- Plot array of Figures Mathplotlib
- data type in Julia and MLJ
Related Questions in LINEAR-ALGEBRA
- Bound for product of matrices
- How to get scaling from transformation matrix
- Mahalanobis distance computation in Python
- Iterative Matrix-Vector Product Eigensolvers in Python
- How to Implement Back Substitution for Solving Linear Systems in Python?
- How to get integer answers while solving a chemical equation using Numpy
- is numpy representation a column vector?
- what is the direct method of finding nth power value of matrix say A is 2x2 matrix with say 2 2 3 4 values...now i want [A] ^n
- Move the points in the graph linearly when a point is moved up/down and edge values should be fixed in Javascript
- chol(x,pivot=TRUE) does not have attribute pivot in R
- How to tell when calculating an Intercept Point between two moving objects, when it will never intercept?
- Why do I get back different eigenvectors that I put in?
- Trying to use scipy to solve system of linear equations but having trouble
- Extrinsic camera matrix if translation performs before rotation
- Ensure trivial solution is found to matrix equation
Related Questions in NUMERICAL-METHODS
- Checking Event in solve_ivp
- Scipy solve_ivp extremely slow/freezing
- Error in `*.default`(y, wts) : non-numeric argument to binary operator -> both are numeric?
- Find the first three terms in a geometric series using the given sum and product
- Variable input inside a function
- Backward in time integration of numerical ODE
- Hexahedral mesh creation and adjustment for modeling of a 3D printing process
- Runge-Kutta method to solve Lane-Emden equation
- How to mitigate floating point error in recursive DSP calculations
- OpenMP parallelization is highly inefficient
- How to code in R, this log-likelihood function
- How to implement Carleman Matrix in Haskell?
- How to correctly implement homogenous Neumann boundary conditions in my linear solver?
- Error vs time complexity in big-O notation
- How to debug fourth-order Runge-Kutta for a differential equation in Python
Related Questions in SCIENTIFIC-COMPUTING
- Improve speed of summing up loop in python
- scipys quadrature function complains about perfectly sane lambda?
- Get FEM, save plot as PNG?
- Assigning pre-allocated array to pointer in class constructor C++
- Physics Informed Neural Networks: negative solution and not converging to the right soln.?
- How to resolve warning related to deprecated armadillo function in C++
- Save all intermediate variables in a function, should the function fail
- Matrix input in Julia?
- How can I install the FeniCS dolfin module?
- Randomly generate signed permutation matrix in Julia?
- Generate array of complex numbers with absolute value one in Julia?
- Efficient/Cheap way to concatenate arrays in Julia?
- Reduce number of allocations in matrix multiplication in Julia?
- How to use qrfact function in Julia?
- Is there a correct way to uniformly quantize a color map?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
The result matrix has only
nnonzero entries, so it is going to be sparse. So it might as well be generated as a sparse matrix:Example usage:
Storage-wise this is much better than a full matrix, and the generation speed is also better, the bigger the matrix is.
ADDITION: This is common enough to appear in another package
LuxurySparse.jlwith even simpler definition possible:This package is even more efficient and might warrant a look depending on optimization required. A link: LuxurySparse package doc