Posts

Unity gameobject not destroying

Image
0 I'm building some somtware that displays a text every time you load a certain screen. I'm trying to delete all previous text so that I can load new text every time I load the view. But for some reason I can't seem to destroy the gameobjects holding the text, and ends up duplicating the text I already had. private void SetPages(List<string> strings) { Clear(); foreach (string page in strings) AddPage(page); } private void AddPage(string text) { Text page = instantiator.InstantiatePrefabForComponent<Text>(textPrefab); page.GetComponent<Text>().text = text; page.transform.SetParent(root, false); texts.Add(page); } private void Clear() { if(texts != null) { foreach (Text text in texts) { oldTexts.A...

K Mean Clustering from scratch (Python)

Image
-1 import numpy as np import matplotlib.pyplot as plt from matplotlib import style import pandas as pd import time start_time = time.time() style.use('ggplot') class K_Means: def __init__(self, k =3, tolerance = 0.0001, max_iterations = 500): self.k = k self.tolerance = tolerance self.max_iterations = max_iterations def fit(self, data): self.centroids = {} #initialize the centroids, the first 'k' elements in the dataset will be our initial centroids for i in range(self.k): self.centroids[i] = data[i] #begin iterations for i in range(self.max_iterations): self.classes = {} for i in range(self.k): self.classes[i] = #find the distance between the point and cluster; choose the ne...