从文件中读取值并将其传递给二维数组 [英] reading value from file and passing it to double dimensional array

查看:78
本文介绍了从文件中读取值并将其传递给二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Accord.MachineLearning;
using Accord.Imaging;
using Accord.Math;
using Accord.Statistics;
using System.Windows.Forms;
using System.IO;

namespace DriverApp
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
         KMeans kmeans = new KMeans(3);
          String line;
            try
            {
                //Pass the file path and file name to the StreamReader constructor
                StreamReader sr = new StreamReader(@"D:\input.txt");

                //Read the first line of text
                line = sr.ReadLine();

                //Continue to read until you reach end of file
                while (line != null)
                {
                    //write the lie to console window
                     
                     int[] medoid =kmeans.Compute(line); // here i am getting error
                   
                    //Read the next line
                    line = sr.ReadLine();
                }

                //close the file
                sr.Close();
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing finally block.");
            }

        
           
   
           // KMeans kmeans = new KMeans(3);

            // Compute the algorithm, retrieving an integer array
            //  containing the labels for each of the observations
           // int[] medoid = kmeans.Compute(observations);
            
            
           
            // As a result, the first two observations should belong to the
            //  same cluster (thus having the same label). The same should
            //  happen to the next four observations and to the last three.

            Console.Write("The most efficient prediction via K-Means is : ");
            for (int counter = 0; counter < medoid.Length; counter++)
            {
               Console.Write(medoid[counter] + " ");
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();


        }
    }
}


这是我要隐含的代码,
实际上我正在尝试从文件中读取值并将其传输到k均值算法,但是它通常使用double值,如何将文件中的字符串值转换为k均值所需的double值
我得到的错误是double [] []有一些无效的参数
请帮我解决这个问题


This is the code I am trying to impliment,
Actually I am trying to read values from file and transfer it to k means algorithm, but it oly takes double value,how should I convert string value taken from file to double value required by k means
error i am getting is double[][] had some invalid arguments
please help me out this prob

推荐答案

可以使用 ^ ]


这篇关于从文件中读取值并将其传递给二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆