jagged-arrays

Reading data from a CSV to an array of arrays (C#)

∥☆過路亽.° 提交于 2019-12-02 10:48:25
I have the CSV file opened, but I can't figure out how to put the resultant array from splitting the line into another array. I have the following code currently, hopefully it gives more of an idea of what I'm meaning: private void ReadFileToArray(StreamReader file) { int i = 0; string[][] FP_GamesArray; while (!file.EndOfStream) { string line = file.ReadLine(); if (!String.IsNullOrWhiteSpace(line)) { string[] values = line.Split(','); MessageBox.Show(values.ToString()); FP_GamesArray[i] = values; } i++; } } Any ideas? I get two errors: One saying Cannot implicitly convert type 'string[]' to

How can I concatenate vectors to create non-rectangular matrices in MATLAB?

折月煮酒 提交于 2019-12-02 09:04:14
Is there a way to create non-rectangular matrices? For example, if I have a matrix a=[6 8 10] and another matrix b=[1 5] , can I vertically concatenate them in order to obtain [6 8 10] in one row and [1 5] in another? rayryeng The direct answer is no . MATLAB does not support ragged or non-rectangular or non-square matrices . One way you could get around this is to make a cell array, where each cell is a vector of unequal lengths. Something like: a = [6 8 10]; b = [1 5]; c = cell(1,2); c{1} = a; c{2} = b; celldisp(c) c{1} = 6 8 10 c{2} = 1 5 Another way would be to create a matrix where those

how to inset a new array to my jagged array

房东的猫 提交于 2019-12-02 05:36:02
hello i will much apreciate any help. ok let's see, first i have declare a jagged array like this and the next code int n=1, m=3,p=0; int[][] jag_array =new[n]; now my jagged array will have 1 array inside, next y have to fill the array like this: car=2; do { jag_array[p]= new double[car]; for (int t = 0; t < carac; t++) { jag_array[p][t] = variableX; } p=p+1 } while(p==0) now my jagged array looks like this(also insert some data for this example): jag_array[0][0]=4 jag_array[0][1]=2 now my question how can i insert a new array whit out losing my previos data if i declare jag_array[p+1]= new

How to delete zeros from matrix in MATLAB?

∥☆過路亽.° 提交于 2019-12-01 22:11:10
Here is my problem: I have a nxn matrix in matlab. I want to delete all the zeros of this matrix and put the rows of it in vectors. For n=4 , let say I have the following matrix: A = [ 1 1 0 0 1 2 0 0 1 0 0 0 1 2 1 0 ]; How to get the following: v1 = [ 1 1 ]; v2 = [ 1 2 ]; v3 = [ 1 ]; v4 = [ 1 2 1 ]; I did the following: for i = 1:size(A, 1) tmp = A(i, :); tmp(A(i, :)==0)=[]; v{i} = tmp; end Luis Mendo Slightly faster than Divakar's answer : nzv = arrayfun(@(n) nonzeros(A(n,:)), 1:size(A,1), 'uniformoutput', false); Benchmarking Small matrix A = randi([0 3],100,200); repetitions = 1000; tic

Fixed statement with jagged array

爷,独闯天下 提交于 2019-12-01 21:41:48
I have jagged array which I need to pass to external method. [DllImport(...)] private static extern int NativeMethod(IntPtr[] ptrArray); ... fixed (ulong* ptr = array[0]) { for (int i = 0; i < array.Length; i++) { fixed (ulong* p = &array[i][0]) { ptrArray[i] = new IntPtr(p); } } NativeMethod(ptrArray); } The problem is that ptr is unused and is removed due compilation. Than fixed statement according to it is removed too. So array be moved by GC in that way that ptrArray elements become invalid. What is the best way for passing jagged arrays as single-dimensional arrays of pointers to native

Unexpected behavour when making array of 2D arrays, of similar dimension

妖精的绣舞 提交于 2019-12-01 21:39:51
MWE: def showArrayOfList(a,b,c): wlist = [np.zeros((szNext,szThis)) for (szThis,szNext) in [(a,b),(b,b),(b,b),(b,c)]] print "wlist:", map(np.shape,wlist) wArray = np.asarray(wlist) print "wArray:", map(np.shape,wArray) print "shape wArray:", shape(wArray) np.zeros can be substituted for any other matrix function that returns a matrix given a shape The output from the following is what I expect (and get): In[1]: ShowArrayOfList(1,4,5) Out[1]: wlist: [(4, 1), (4, 4), (4, 4), (5, 4)] wArray: [(4, 1), (4, 4), (4, 4), (5, 4)] shape wArray: (4,) #An array of 4 references(?), to arrays of various

Are there any problems with using jagged-arrays in Fortran with multiple levels of allocation?

旧城冷巷雨未停 提交于 2019-12-01 18:03:46
问题 In my Fortran code, I want to use jagged arrays with multiple levels of allocation. An example code of what I mean is module nonsquare_matrix_mod implicit none type :: nonsquare_matrix integer :: d real*8, dimension(:), allocatable :: vector end type nonsquare_matrix type(nonsquare_matrix),dimension(:),allocatable :: mymatrix end module nonsquare_matrix_mod program nonsquare_matrix_test use nonsquare_matrix_mod implicit none integer, parameter :: max_size=50 integer :: i allocate(mymatrix(max

Avoiding Agnostic Jagged Array Flattening in Powershell

孤人 提交于 2019-12-01 05:46:28
I'm running into an interesting problem in Powershell, and haven't been able to find a solution to it. When I google (and find things like this post ), nothing quite as involved as what I'm trying to do comes up, so I thought I'd post the question here. The problem has to do with multidimensional arrays with an outer array length of one. It appears Powershell is very adamant about flattening arrays like @( @('A') ) becomes @( 'A' ) . Here is the first snippet (prompt is >, btw): > $a = @( @( 'Test' ) ) > $a.gettype().isarray True > $a[0].gettype().isarray False So, I'd like to have $a[0]

Fastest way to convert T[,] to T[][]?

て烟熏妆下的殇ゞ 提交于 2019-12-01 04:13:05
So it turns out all arrays are not created equal. Multi-dimensional arrays can have non-zero lower bounds. See for example Excel PIA's Range.Value property object[,] rectData = myRange.Value; I need to convert these data into a jagged array. My first try below smells of complexity. Any suggestions to optimize it? It needs to handle the general case where lower bounds may not be zero. I have this ex method: public static T[][] AsJagged<T>( this T[,] rect ) { int row1 = rect.GetLowerBound(0); int rowN = rect.GetUpperBound(0); int col1 = rect.GetLowerBound(1); int colN = rect.GetUpperBound(1);

Fastest way to convert T[,] to T[][]?

点点圈 提交于 2019-12-01 00:33:14
问题 So it turns out all arrays are not created equal. Multi-dimensional arrays can have non-zero lower bounds. See for example Excel PIA's Range.Value property object[,] rectData = myRange.Value; I need to convert these data into a jagged array. My first try below smells of complexity. Any suggestions to optimize it? It needs to handle the general case where lower bounds may not be zero. I have this ex method: public static T[][] AsJagged<T>( this T[,] rect ) { int row1 = rect.GetLowerBound(0);