One is an array of arrays, and one is a 2d array. The former can be jagged, the latter is uniform.
That is, a double[][] can validly be:
double[][] x = new double[5][];
x[0] = new double[10];
x[1] = new double[5];
x[2] = new double[3];
x[3] = new double[100];
x[4] = new double[1];
Because each entry in the array is a reference to an array of double. With a jagged array, you can do an assignment to an array like you want in your second example:
x[0] = new double[13];
On the second item, because it is a uniform 2d array, you can't assign a 1d array to a row or column, because you must index both the row and column, which gets you down to a single double:
double[,] ServicePoint = new double[10,9];
ServicePoint[0]... // <-- meaningless, a 2d array can't use just one index.
UPDATE:
To clarify based on your question, the reason your #1 had a syntax error is because you had this:
double[][] ServicePoint = new double[10][9];
And you can't specify the second index at the time of construction. The key is that ServicePoint is not a 2d array, but an 1d array (of arrays) and thus since you are creating a 1d array (of arrays), you specify only one index:
double[][] ServicePoint = new double[10][];
Then, when you create each item in the array, each of those are also arrays, so then you can specify their dimensions (which can be different, hence the term jagged array):
ServicePoint[0] = new double[13];
ServicePoint[1] = new double[20];
Hope that helps!
2016년 4월 11일 월요일
Accord 를 이용한 엑셀 파일 import 하는 코드
public double[][] Inputs ;
public int[] Outputs ;
public void ImportExcelData()
{
OpenFileDialog of = new OpenFileDialog();
if (of.ShowDialog() == DialogResult.OK)
{
TDataTable = new ExcelReader(of.FileName).GetWorksheet("Classification - Yin Yang");
}
double[][] input = TDataTable.ToArray
int[] output = TDataTable.Columns["G"].ToArray
ScatterplotBox.Show("TT", input, output).Hold();
WriteData2Field(input, output);
}
[C#] 파일 경로 불러오는법
경로는 다음과 같이 되어야 된다.
"C:\\Users\\SJW\\Desktop\\Local project\\알고리즘 예제\\Logistic\\LogisticClassification\\LogisticClassification\\data\\examples.xls"
string fileName = "examples.xls";
1번째 방법
string path = Path.Combine(Environment.CurrentDirectory, @"data\", fileName); // 여기선 디버그 폴더안의 example.xls를 가져올떄
2번째 방법
string path = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName; // bin 폴더 전,즉 프로젝트메인 폴더까지
string combinedpath = Path.Combine(path, "data", fileName);
TDataTable = new ExcelReader(combinedpath).GetWorksheet("Classification - Yin Yang");
3번째
using System.Windows.Forms; 을 사용해서 (레퍼런스에 추가 필수 )
if (of.ShowDialog() == DialogResult.OK)
{
TDataTable = new ExcelReader(of.FileName).GetWorksheet("Classification - Yin Yang");
}
이렇게도 가능하다.
"C:\\Users\\SJW\\Desktop\\Local project\\알고리즘 예제\\Logistic\\LogisticClassification\\LogisticClassification\\data\\examples.xls"
string fileName = "examples.xls";
1번째 방법
string path = Path.Combine(Environment.CurrentDirectory, @"data\", fileName); // 여기선 디버그 폴더안의 example.xls를 가져올떄
2번째 방법
string path = new DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName; // bin 폴더 전,즉 프로젝트메인 폴더까지
string combinedpath = Path.Combine(path, "data", fileName);
TDataTable = new ExcelReader(combinedpath).GetWorksheet("Classification - Yin Yang");
3번째
using System.Windows.Forms; 을 사용해서 (레퍼런스에 추가 필수 )
if (of.ShowDialog() == DialogResult.OK)
{
TDataTable = new ExcelReader(of.FileName).GetWorksheet("Classification - Yin Yang");
}
이렇게도 가능하다.
Accord Setting
Install Accrod From Nuget
Need
Accord
Accord.Io
Accord.MachineLearning
Accord.Statics
Accord.Control
Accord.Math
Need
Accord
Accord.Io
Accord.MachineLearning
Accord.Statics
Accord.Control
Accord.Math
2016년 4월 7일 목요일
파이썬 행렬생성 numpy.linspace
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
>>> np.linspace(2.0, 3.0, num=5)
array([ 2. , 2.25, 2.5 , 2.75, 3. ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
array([ 2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
ex )
n = 100
x = np.linspace(0, 2 * math.pi, n)
y = np.sin(x) + 0.3 * np.random.randn(n)
x는 1 x 100 의 행렬 (n이 100 이므로)
y는 100의 포인트에 노이즈가 들어간 사인 그래프가 된다.
>>> np.linspace(2.0, 3.0, num=5)
array([ 2. , 2.25, 2.5 , 2.75, 3. ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
array([ 2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
ex )
n = 100
x = np.linspace(0, 2 * math.pi, n)
y = np.sin(x) + 0.3 * np.random.randn(n)
x는 1 x 100 의 행렬 (n이 100 이므로)
y는 100의 포인트에 노이즈가 들어간 사인 그래프가 된다.
피드 구독하기:
글 (Atom)