add csv import
This commit is contained in:
18
KMeansBase/Csv.cs
Normal file
18
KMeansBase/Csv.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace KMeansBase;
|
||||
|
||||
public class Csv
|
||||
{
|
||||
public static IEnumerable<Point> Parse(string path)
|
||||
{
|
||||
var lines = File.ReadLines(path);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var current = line.Split(',');
|
||||
if (!double.TryParse(current[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var x)) continue;
|
||||
if (!double.TryParse(current[1], NumberStyles.Any, CultureInfo.InvariantCulture, out var y)) continue;
|
||||
yield return new Point(x, y, -1);
|
||||
}
|
||||
}
|
||||
}
|
@ -74,7 +74,6 @@ public static class KMeans
|
||||
var x = (minX + maxX) * rnd.NextDouble();
|
||||
var y = (minY + maxY) * rnd.NextDouble();
|
||||
var point = new Point(x, y, i);
|
||||
Console.WriteLine(point);
|
||||
yield return point;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user