Esempio n. 1
0
from NumPyCreator import NumPyCreator

npc = NumPyCreator()
#print(npc.from_list([[1,2,3],[6,3,4]]))
#print(npc.from_tuple(("a", "b", "c")))
#print(npc.from_iterable(range(5)))
shape=(3,5)
print(npc.from_shape(shape))
shape=(3,5)
print(npc.from_shape(shape, 3))
print(npc.random(shape))
print(npc.identity(4))
Esempio n. 2
0
    def mean_blur(self, array3D, size=(3, 3)):
        kernel = np.full(size, 1)
        new = np.copy(array3D)

        for y in enumerate(array3D):
            if y[0] >= size[1] - 1 and y[0] < new.shape[0] - 1:
                for x in enumerate(y[1]):

                    if x[0] >= size[1] - 1 and x[0] < new.shape[1] - 1:

                        new[y[0]][x[0]] = self.make_kernel(
                            kernel, array3D, size, (y[0], x[0]))

        return (new)


if __name__ == "__main__":
    imp = ImageProcessor()
    npc = NumPyCreator()
    af = AdvancedFilter()

    array = imp.load('./Fourmisse.png')
    imp.display(array)
    test = np.random.randint(9, size=(8, 8))
    print(test)
    #imp.display(array)
    arr = af.mean_blur(array)
    print(arr)
    print('\n', test)
    imp.display(arr)
Esempio n. 3
0
            print("dimmension error")
            exit(0)

    def thin(self, array, n, axis=0):
        return np.delete(array, np.s_[n::n], axis)

    def juxtapose(self, array, n, axis=0):
        array = np.concatenate((array, array), axis=0)
        for i in range(n):
            if axis == 1:
                array = np.concatenate((array, array), axis=0)
            else:
                array = np.concatenate((array, array), axis=1)
        return array

    def mosaic(self, array, dimensions):
        array = self.juxtapose(array, dimensions[0], 0)
        array = self.juxtapose(array, dimensions[1], 1)
        return array


if __name__ == "__main__":
    nc = NumPyCreator()
    sb = ScrapBooker()
    arra = nc.from_list([[0, 7, 6, 8, 9], [1, 2, 3, 4, 5], [2, 4, 3, 2, 1],
                         [3, 7, 6, 8, 9], [4, 2, 3, 4, 5], [5, 4, 3, 2, 1],
                         [6, 7, 6, 8, 9], [7, 2, 3, 4, 5], [8, 4, 3, 2, 1]])

    arra = nc.identity(20)
    print(sb.crop(arra, (2, 2)))
Esempio n. 4
0
#!/usr/bin/python

from NumPyCreator import NumPyCreator

npc = NumPyCreator()

print(npc.from_list([[1, 2, 3], [6, 3, 4]]))
print(npc.from_tuple(("a", "b", "c")))
print(npc.from_iterable(range(5)))
shape = (3, 5)
print(npc.from_shape(shape))
print(npc.random(shape))
print(npc.identity(4))
Esempio n. 5
0
from NumPyCreator import NumPyCreator

npc = NumPyCreator()

a = npc.from_list([[1, 2, 3], [6, 3, 4]])
print(type(a))

b = npc.from_tuple((1, 5, 6))
print(b)

c = npc.from_iterable(range(5))
print(c)
print(type(c))

t = (5, 7)
d = npc.from_shape(t)
print(d)
print(type(c))

e = npc.random(t)
print(e)

f = npc.identity(5)
print(f)
Esempio n. 6
0
from NumPyCreator import NumPyCreator
npc = NumPyCreator()

#init colors
red = "\x1b[1;3{};40m".format(1)
green = "\x1b[1;3{};40m".format(2)
yellow = "\x1b[1;3{};40m".format(3)
blue = "\x1b[1;3{};40m".format(4)
purple = "\x1b[1;3{};40m".format(5)
teal = "\x1b[1;3{};40m".format(6)
back = "\x1b[0m"


#from list
print("\n{}{}{}".format(blue, "from_list", back))
entry = [[1,2,3],[6,3,4]]

print("  {purple}entry: {back}{} {yellow}no type{back}".format(entry, purple = purple, yellow = yellow, back = back))
result = npc.from_list(entry)
print("  {teal}result:{back} \n{}\n{teal}  type:{back} {}".format(result, type(result), teal = teal, back = back))

entry = ([7, 8, 10])
print("\n  {purple}entry: {back}{} {yellow}complex{back}".format(entry, purple = purple, yellow = yellow, back = back))
result = npc.from_list(entry, dtype=complex)
print("  {teal}result:{back} \n{}\n{teal}  type:{back} {}".format(result, type(result), teal = teal, back = back))


#from tuple
print("\n{}{}{}".format(blue, "from_tuple", back))
entry = ("a", "b", "c")
Esempio n. 7
0
    def random(self, array):

        npc = NumPyCreator()
        shape = npc.random((array.shape[0], array.shape[1]))
        array = array * shape
        return array
Esempio n. 8
0
    def fit(self, X):
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        x_points = X[:, 0]
        y_points = X[:, 1]
        z_points = X[:, 2]
        ax.scatter3D(x_points, y_points, z_points, color='black')

        def print_centroids(ax, centroids):
            plot = numpy.array(centroids)
            col = {0: 'orange', 1: 'green', 2: 'blue', 3: 'pink', 4: 'yellow'}
            for element in plot:
                x_pts = element[0]
                y_pts = element[1]
                z_pts = element[2]
                ax.scatter3D(x_pts, y_pts, z_pts, marker='*', color=col[x])
            # x_pts = plot[:,0]
            # y_pts = plot[:,1]
            # z_pts = plot[:,2]
            # ax.plot3D(x_pts, y_pts, z_pts, color='green')
            # x_pts = plot[2,:,0]
            # y_pts = plot[2,:,1]
            # z_pts = plot[2,:,2]
            # ax.plot3D(x_pts, y_pts, z_pts, color='blue')
            # x_pts = plot[3,:,0]
            # y_pts = plot[3,:,1]
            # z_pts = plot[3,:,2]
            # ax.plot3D(x_pts, y_pts, z_pts, color='pink')
            pass

        """
        Run the K-means clustering algorithm.
        For the location of the initial centroids, random pick ncentroids from the dataset.
        Args:
            X: has to be an numpy.ndarray, a matrice of dimension m * n.
        Returns:
            None.
        Raises:
            This function should not raise any Exception.
        """

        def get_L1_dist(a, b):
            dist = numpy.zeros(len(b))
            for i in range(len(b)):
                dist[i] = abs(b[i][0] - a[0]) + abs(b[i][1] -
                                                    a[1]) + abs(b[i][2] - a[2])
                # dist[i] = (pow(b[i][0] - a[0], 2) + pow(b[i][1] - a[1],2) + pow(b[i][2] - a[2],2))**(1./3.)
            return dist

        self.centroids = random.choices(X.tolist(), k=self.ncentroid)
        npc = NumPyCreator()
        self.centroids = npc.from_list(self.centroids, dtype=float)
        clusters = numpy.zeros(len(X), dtype=float)
        x = self.ncentroid  # nombre d'iterations
        while x > 0:
            # Pour chaque X[i] on attribue la distance minimum entre centroide et X[i] au clusters[i] correspondant a chaque centroides
            for i in range(len(X)):  # parcours le tableau X
                distances = get_L1_dist(
                    X[i], self.centroids
                )  # Calcul la distance entre X[i] et chaques centroides donnant chques distances par rapport a chaque centroides
                clusters[i] = numpy.argmin(
                    distances
                )  # Prend l'indice du centroid ayant la distance le plus petite pour le point i de cluster
            # pour chaque centroid[i] on cherche la moyenne des points les plus proches du centroide
            # print(clusters)
            for i in range(self.ncentroid):
                points = [
                    X[j] for j in range(len(X)) if clusters[j] == i
                ]  # on prend le X[i] si l'indice du cluster correspond a l'indice du centroide
                # points = npc.from_list(points, dtype=float)
                self.centroids[i] = numpy.mean(
                    points, axis=0, dtype=float
                )  # Moyenne des points pour calculer le nouveau centroide
            x -= 1
            print_centroids(ax, self.centroids)
Esempio n. 9
0
            if (cent_cpy[i][3] != slender_min and cent_cpy[i][0] != height_max
                    and
                ((cent_cpy[((i + 1) % 3)][3] < cent_cpy[i][3] and cent_cpy[(
                    (i + 2) % 3)][0] > cent_cpy[i][0]) or
                 (cent_cpy[((i + 2) % 3)][3] < cent_cpy[i][3] and cent_cpy[(
                     (i + 1) % 3)][0] > cent_cpy[i][0]))):
                earth_height = cent_cpy[i][0]
                cent_cpy.remove(cent_cpy[i])

        print("Belt", Belt)

        # centroids = numpy.delete(centroids, Belt[0], axis=0)
        # print(centroids)
        # Venus = numpy.where(centroids[:,1] == numpy.amin(centroids[:,1]))
        # print(Venus)
        # centroids = numpy.delete(centroids, Venus[0], axis=0)
        # Mars = numpy.where(centroids[:,0] == numpy.amax(centroids[:,0]))
        # centroids = numpy.delete(centroids, Mars[0], axis=0)


if __name__ == "__main__":
    kmean = KmeansClustering(ncentroid=4)
    with CsvReader('solar_system_census.csv', header=True) as file:
        data = file.getdata()
        npc = NumPyCreator()
        data_array = npc.from_list(data, dtype=float)
        # print(data_array)
        kmean.fit(data_array)
        kmean.predict(data_array)
    pass
Esempio n. 10
0
from NumPyCreator import NumPyCreator
npc = NumPyCreator()

# a = npc.from_list([[1,2,3],[6,3,4]])
# a = npc.from_tuple(("a", "b", "c"))
# a = npc.from_iterable(range(5))

shape = (3, 5)
# a = npc.from_shape(shape,2)

# a = npc.random(shape)
a = npc.identity(4)

print(a)
print(type(a))
Esempio n. 11
0
from NumPyCreator import NumPyCreator

npc = NumPyCreator()
my_array = npc.from_list([[1, 4, 2, 5, 7], [8, 0, 1, 9, 2]])
print(type(my_array))
print(my_array)

my_array = npc.from_tuple((2, 3))
print(type(my_array))
print(my_array)

my_array = npc.from_iterable(range(510))
print(type(my_array))
print(my_array)

shape = (2, 6)
my_array = npc.from_shape(shape, int)
print(type(my_array))
print(my_array)

my_array = npc.random(shape)
print(type(my_array))
print(my_array)

my_array = npc.identity(4)
print(type(my_array))
print(my_array)
Esempio n. 12
0
from NumPyCreator import NumPyCreator

npc = NumPyCreator()
print(npc.from_list([1, 2, 3, 6, 3, 4]))  # My test
print(npc.from_list([[1, 2, 3], [6, 3, 4]]))
# Output:
# array([[1, 2, 3],
# 	   [6, 3, 4]])

print(npc.from_list([[1, 2, 3], [6, 4]]))
# Output
# None

print(npc.from_list([[1, 2, 3], ['a', 'b', 'c'], [6, 4, 7]]))
print(npc.from_list([[1, 2, 3], ['a', 'b', 'c'], [6, 4, 7]]).dtype)
# Output
# array([['1', '2', '3'],
# ['a', 'b', 'c'],
# ['5.0', '6.1', '7.8']], dtype='<U21')  # U21 = Unicode string with 21 char or less
#
print(npc.from_list(((1, 2), (3, 4))))
# Output
# None

print(npc.from_tuple(("a", "b", "c")))
print(npc.from_tuple((("a", "b", "c"), ("d", "e", "f"))))  # my test
# Output
# array(['a','b','c'])

print(npc.from_tuple([[1, 2, 3], [6, 3, 4]]))
# Output