Suppose I have the inputs data = [1 2 3 4 5 6 7 8 9 10]
and num = 4. I want to use these to generate the following:
i = [1 2 3 4 5 6; 2 3 4 5 6 7; 3 4 5 6 7 8; 4 5 6 7 8 9]
o = [5 6 7 8 9 10]
which is based on the following logic:
length of data = 10
num = 4
10 - 4 = 6
i = [first 6; second 6;... num times]
o = [last 6]
What is the ...
Hi everyone,
I'v been bored so I created a small console minesweeper game and while writting it I had to find the neighbor positions of an element in a size*size matrix which is represented as an vector of elements and one variable which holds the size value. I didn't want to return the actual values of the neighbor elements but their p...
Given an n-dimensional matrix of values: what is the most efficient way of retrieving values by arbitrary indices (i.e. coordinates)?
E.g. in a random 5x5 matrix, if I want the values at (1,1) (2,3) and (4,5) what is the most efficient way of returning just the values at these coordinates?
If I provide these coordinates in a separate m...
I'm developing a program for class that reads a matrix and then prints it with an identity matrix. Then step by step I have to reduce it into its identity matrix while applying the same calculations onto the identity matrix and therefore getting the inverse of that matrix.
I'm stuck at the row reducing section of the code. I'm trying t...
A simple 2 dimensional array allows swapping rows (or columns) in a matrix in O(1) time. Is there an efficient data structure that would allow swapping both rows and columns of a matrix in O(1) time?
...
I am trying to create a checking program to see if the word is in a matrix horizontally or vertically. I have the code for checking the row, but would checking the column be similar to the row code?
def checkRow(table, r, pos, word):
for i in range(0, len(word)):
if table[r][pos+i] != word[i]:
return False
re...
I need to make a 3-D matrix in a MEX file. In the API reference, there is mention of mxCreateCellArray for N-D cell arrays, mxCreateStructArray for structs, etc. But there is no mxCreateDoubleArray mentioned. Is this possible?
...
Hi folks,
I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. Currently, there are 952 places. So the matrix would have 952x952 = 906304 entries.
I tried to map this into a HashMap[Integer, Fl...
I'm getting a weird error when training a glmnet regression.
invalid class "dgCMatrix" object: length(Dimnames[[2]])' must match Dim[2]
It only happens occasionally, and perhaps only under larger datasets.
I'm not sure whether it's consistent it happens given a certain dataset.
Any clues?
...
I need to find the largest square of 1's in a giant file full of 1's and 0's. I know i have to use dynamic programming. I am storing it in a 2D array. Any help with the algorithm to find the largest square would be great, thanks!
ex)
1 0 1 0 1 0
1 0 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
1 1 1 1 1 1
ans:
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
...
I'm having a problem where in the local project preview tab (and when "running" the report from visual studio) both are corrently formatting. However, after deploying to the report server, the formatting doesn't show through at all for the Row and Column group subtotals.
I'm running Visual Studio 2005.
Example:
...
Hi, I followed the tutorial on
http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/ to achieve a camera that follows my player sprite with zoom in/out functionality.
however, when I zoom in/out the camera seems to either slowly move away from the sprite whilst moving, I don't think I'm setting the position right, b...
How do you read the following MATLAB codes?
#1
K>> [p,d]=eig(A) // Not sure about the syntax.
p =
0.5257 -0.8507
-0.8507 -0.5257
d = // Why do you get a matrix?
0.3820 0
0 2.6180
#2
K>> p,d=eig(A) // Not sure ...
This is a method that gets a element from a Sparse Matrix in java. I keep getting a java.lang.NullPointerException error. I have looked over the code and can't find the error.
public int getElement(int row,int col){
int result = 0;
MatrixEntry matrixentry = null;
if ((row >= 0) && (row < getNumRows()) &&
(col >= 0) ...
Suppose we have a m by n matrix A with rank m and a set K⊆{1..n} such that the columns of A indexed by K are linearly independent. Now we want to extend K and find a set L so that k⊆L and columns indexed by L are linearly independent too.
One way of doing it would be to start adding column indexes to K and test if the new set are linear...
#include <array>
template <typename T>
class Vector4<T> {
std::array<T, 4> _a; // or 'T _a[4];'?
};
template <typename T>
class Matrix4<T> {
std::array<T, 16> _a; // or 'T _a[16];'?
//Vector4<T> row0; // or should i use this instead
//Vector4<T> row1; // it makes other code easier but how
//Vector4<T> row2; // can i...
How can I make a simple low-pass FIR filter using Matlab (without using the built-in function) ?
Problem example:
Implement a FIR LPF with cut-off frequency 250Hz
it may also be necessary that, sampling freq is given...
Solution attempt or what I already know:
x = [...] -> input signal
A = 1; -> Since this is FIR
B = [?????]
y = fi...
I am writing R code to create a square matrix. So my approach is:
Allocate a matrix of the correct size
Loop through each element of my matrix and fill it with an appropriate value
My question is really simple: what is the best way to pre-allocate this matrix? Thus far, I have two ways:
> x <- matrix(data=NA,nrow=3,ncol=3)
> x
...
I'm trying to implement a geometry templating engine. One of the parts is taking a prototypical polygonal mesh and aligning an instantiation with some points in the larger object.
So, the problem is this: given 3d point positions for some (perhaps all) of the verts in a polygonal mesh, find a scaled rotation that minimizes the differen...
I'm looking for some pointers here as I don't quite know where to start researching this one.
I have a 2D matrix with 0 or 1 in each cell, such as:
1 2 3 4
A 0 1 1 0
B 1 1 1 0
C 0 1 0 0
D 1 1 0 0
And I'd like to sort it so it is as "upper triangular" as possible, like so:
4 3 1 2
B 0 1 1 1
A 0 1 0 1
D 0 0 1 1
C 0 0 0 1
The row...