matrix

Julia: Sort Matrix by column 2 then 3

僤鯓⒐⒋嵵緔 提交于 2021-02-17 14:47:04
问题 I would like to sort my matrix A by column 2 then 3. A = round.(randn(100,4)) Maybe something like: sort(A,(0,2:3)) 100x4 Array{Float64,2}: 0.0 -2.0 -2.0 -1.0 -1.0 -2.0 -1.0 1.0 1.0 -2.0 -1.0 2.0 -1.0 -2.0 0.0 0.0 -1.0 -2.0 0.0 -1.0 -0.0 -2.0 0.0 -1.0 1.0 -2.0 0.0 0.0 1.0 -2.0 1.0 -1.0 -0.0 -2.0 2.0 -1.0 -0.0 -1.0 -2.0 1.0 ⋮ -0.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 1.0 -1.0 -0.0 1.0 2.0 0.0 -0.0 2.0 -1.0 0.0 -2.0 2.0 -1.0 1.0 2.0 2.0 -0.0 -1.0 -1.0 2.0 -0.0 -1.0 1.0 2.0 0.0 2.0 -1.0 2.0 2.0 0

Print matrix without column names but kept alligned?

非 Y 不嫁゛ 提交于 2021-02-17 05:25:07
问题 I would like to print a matrix without column names and found this answer. However, this will result in the columns of the output not being aligned anymore, when the row names are kept and are of different length: m <- matrix(LETTERS[1:12],nrow = 2, ncol = 6) rownames(m) <- c("First Row", "Second Row") Using print just ignores the col.names = FALSE argument (why?): print(m, col.names=FALSE, quote=FALSE) > [,1] [,2] [,3] [,4] [,5] [,6] > First Row A C E G I K > Second Row B D F H J L Using

Read matrix to 2D array in C/C++

隐身守侯 提交于 2021-02-17 03:17:43
问题 What is the simplest way to read/input a matrix of numbers into an array in C++? This is the file content (dimensions are unknown): 283 278 284 290 290 286 273 266 266 266 261 252 246 382 380 379 381 382 379 384 387 385 382 376 365 357 285 282 281 279 276 273 272 264 255 255 247 243 237 196 190 186 183 183 180 179 186 191 195 195 188 187 245 237 226 220 221 222 225 228 234 245 252 264 272 283 278 284 290 290 286 273 266 266 266 261 252 246 I've tried a lot of suggested codes, but non of them

Extract submatrix at certain row/col values

拜拜、爱过 提交于 2021-02-16 19:03:07
问题 I need to slice a 2D input array from row/col indices and a slicing distance. In my example below, I can extract a 3x3 submatrix from an input matrix, but I cannot adapt this code to work for any search distance I would like, without resorting to manually writing down the indices: Example: import numpy as np # create matrix mat_A = np.arange(100).reshape((10, 10)) row = 5 col = 5 # Build 3x3 matrix around the centre point matrix_three = ((row - 1, col - 1), (row, col - 1), (row + 1, col - 1),

How to swap rows and columns of a 2d array?

早过忘川 提交于 2021-02-15 06:48:52
问题 I'm trying to write a method for 'transpose' a two-dimensional array of integers, in which the rows and columns of the original matrix are exchanged. However, I have no idea how I can realize this. How do I write out this method? public class Matrix { private int[][] numbers; public Matrix(int rows, int colums) { if (rows < 1) rows = 1; else rows = rows; if (colums < 1) colums = 1; else colums = colums; numbers = new int[rows][colums]; } public final void setNumbers(int[][] numbers) { this

OpenCV data of two mats are the same but values when retrieved with Mat::at are corrupted

可紊 提交于 2021-02-11 15:14:51
问题 I serialize and then deserialize a Mat using custom functions. When you compare the uchar* Mat.data of two functions they are the same but when I try to check values directly using Mat.at<> after third element, element values are stuck at some corrupted float values. I tried changing elements to every other value, nothing changed. The problem also doesn't happen when I serialize-deserialize image Mats and histogram Mats. Below is the code and below that is the output. cv::Mat kernelx = (cv:

Numpy matrix rotation for any degrees

做~自己de王妃 提交于 2021-02-11 14:51:18
问题 I try to find a way to apply a matrix rotation of any degrees on my matrix that contains three bands like RGB but values are bigger than (0-255). It is an example of my data its shape is (100, 100, 3): [[ 847.5 877. 886. ... 821.5 856.5 898. ] [ 850. 883. 969.5 ... 885. 878.5 947.5] [ 982. 968.5 927.5 ... 909.5 958. 1037. ] ... [ 912. 827. 893. ... 1335. 1180. 1131. ] [ 954. 855.5 882. ... 1252. 1266. 1335. ] [ 984. 916. 930. ... 1080.5 1278. 1385.5]] I found a function scipy.misc.imrotate

numpy: Print matrix with random elements, columns and rows

旧街凉风 提交于 2021-02-11 14:30:19
问题 I want a matrix to be printed with random columns(0, 9) and random rows(0, 9) with random elements(0, 9) Where (0, 9) is any random number between 0 and 9. 回答1: If what you're looking for is a 10x10 matrix filled with random numbers between 0 and 9, here's what you want: # this randomizes the size of the matrix. rows, cols = np.random.randint(9, size=(2)) # this prints a matrix filled with random numbers, with the given size. print(np.random.randint(9, size=(rows, cols))) Output: [[1 7 1 4 4

create a 20x20 matrix using numpy broadcast

廉价感情. 提交于 2021-02-11 14:24:19
问题 I'm looking how to create a matrix of 20x20 using Numpy broadcasting, result should look like: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 0, 5, 10, 15, 20, 25, 30

Issue with border lines in a matrix report

那年仲夏 提交于 2021-02-11 14:19:43
问题 I have a requirement to display the Product name and the related Amount in a report grouped by each CategoryId (no need to show categoryId in the report, only used in grouping) as shown below. Below are the design steps. Added a matrix with 2 rows and a column grouping by CategoryId In the first row of matrix, added a tablix with 2 columns (Product and Amount) and row grouping on Product. In the second row of matrix, added a tablix with 2 rows (Subtotal and GrandTotal) and 2 columns (Product