예제 #1
0
def OR(x1, x2):
    x = np.array([x1, x2])
    w = np.array([0.5, 0.5])
    tmp = np.sum(w * x)
    if tmp <= 0:
        return 0
    else:
        return 1
예제 #2
0
def NAND(x1, x2):
    x = np.array([x1, x2])
    w = np.array([-0.5, -0.5])
    tmp = np.sum(w * x)
    if tmp <= 0:
        return 0
    else:
        return 1
예제 #3
0
def EtapaAbejasObservadorasMaestras(num):
    m = mejorPosicion(num)
    for i in range(Po):
        while(True):
            k = random.randint(0, Pf-1)  # Número aleatorio  tal que i!=k
            if k != m:
                break
        vm = np.array([0, 0])
        for j in range(D-1):
            r = random.uniform(0, 1)  # random [0,1]
            vm[j] = X[j, m] + r*(X[j, m]-X[j, k])  # vmj = xmj + r*(xmj - xkj)
        if f(num, vm[0], vm[1]) < f(num, X[0, m], X[1, m]):  # si f(vm) < f(xm)
            X[:, m] = vm  # xm = vm
            li[m] = 0  # lm = 0
        else:
            li[m] += 1  # lm = lm +1
예제 #4
0
def EtapaAbejasEmpleadasAlumnas(num):
    for i in range(Pf):
        while(True):
            k = random.randint(0, Pf-1)  # Número aleatorio  tal que i!=k
            if k != i:
                break
        vi = np.array([0, 0])
        if f(num, X[0, i], X[1, i]) < f(num, X[0, k], X[1, k]):  # Si f(xi) < f(xk)
            for j in range(D-1):
                r = random.uniform(0, 1)  # random [0,1]
                vi[j] = X[j, i]+r*(X[j, i]-X[j, k])  # cij = xij + r*(xij-xkj)
        else:
            for j in range(D-1):
                r = random.uniform(0, 1)  # random [0,1]
                vi[j] = X[j, i]+r*(X[j, k]-X[j, i])  # cij = xij + r*(xkj-xij)
        if f(num, vi[0], vi[1]) < f(num, X[0, i], X[1, i]):  # si f(vi) < f(xi)
            X[:, i] = vi  # xi = vi
            li[i] = 0  # li =0
        else:
            li[i] += 1  # li = li+1
예제 #5
0
#In this Article i gone Elaborate, How to create 1,2,3D Array Manually in Numpy And HOW we Create 1,2,3D Random Number Numpy Array.

import Numpy as np

#creation of 1,2,3D Arrays Manually

#1D Array
#Example
a = np.array([1, 2, 3])
#output
array([1, 2, 3])

#2D Array(it is list of lists)
a = np.array([[1, 2, 3], [4, 5, 6]])
#output
array([[1, 2, 3], [4, 5, 6]])

#3D Array(it is list of lists)
#Example
a = np.array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]],
              [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]])

#output
array([[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]],
       [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]])

#Let's start how to create random Numpy Array (Three ways to get random Array in numpy)

#first way Using numpy.random.rand()
#(By this we can create Random number Array and all the numbers in between 0,1)
#Syntex
예제 #6
0

RANGO = 50
D = 2

POBLACION = 50
GENERACIONES = 150
L = 20
Pf = 30  # Abejas empleadas
Po = POBLACION - Pf  # Abejas observadoras

X = np.zeros((2, Pf))  # Fuentes de Alimento
li = np.zeros(Pf)
apt = np.zeros(POBLACION)   # inicializa arreglo de aptitudes

xl = np.array([-10, -10])  # límite inferior
xu = np.array([10, 10])  # Límite superior


def inicializa():
    for i in range(Pf):
        X[:, i] = xl+(xu-xl)*rand()  # Inicializa fuentes aleatoriamente


def EtapaAbejasEmpleadasAlumnas(num):
    for i in range(Pf):
        while(True):
            k = random.randint(0, Pf-1)  # Número aleatorio  tal que i!=k
            if k != i:
                break
        vi = np.array([0, 0])
# Binary function
def BF(x):
    if x > 0:
        return 1
    return 0


# output function
def OF(x):
    if x:
        return True
    return False


w = np.array([-2, 1, 2])
N = 0.001
Input = [(1, 1, 1), (1, 0, 1), (0, 1, 1), (0, 0, 1)]
test_input = np.array([[1, 1, 1], [1, 0, 1], [0, 1, 1], [0, 0, 1]])
correct_output = [True, False, False, False]
#show dataset to know if linear or not
import matplotlib.pyplot as plt
x = np.array([[1, 1], [1, 0], [0, 1], [0, 0]])
y = [True, False, False, False]
for t in range(4):
    if y[t] == True:
        plt.scatter(x[t][0], x[t][1], alpha=0.8, c='r')
    else:

        plt.scatter(x[t][0], x[t][1], alpha=0.8, c='y')
plt.show()
예제 #8
0
#randn(행,열) : 다차원배열, 정규분포를 따르는 난수 생성
#array(리스트):다차원배열 생성
#arrange : 0~(n-1) 정수 생성

import Numpy as np
from Numpy import genfromtxt  #텍스트 파일을 배열로 생성


data = np.random.rand(3,4)   #3*4행렬에 난수 생성
print(data)

lotto=np.random.randint(46,size=(3,6))  #3*6행렬에 난수 생성
print(lotto)

list=[3,4.1,5,6.3,7,8.6]      #단일 리스트
arr=np.array(list)


print('평균',arr.mean())      #기술통계
print('합계',arr.sum())
print('합계',np.count_nonzero(arr))
print('최대값',arr.max())
print('최소값',arr.min())
print('분산',arr.var())
print('표준편차',arr.std())

list = [[9,8,7,6,5],[1,2,3,4,5] ]  #중첩리스트
arr = np.array(list)
print(arr)
print(arr[0,2])     #7
print(arr[1,3])     #4
예제 #9
0
import Numpy as np

intarr = np.array([[1, 2, 4][3, 5, 4]])
print("integer array")
print(intarr)
print("")

floatarr = np.array([[2, 9, 8][7, 9, 7]])
print("floatarray")
print(floatarr)
print("")

complexarr = np.array([[1, 3, 4][4, 3, 6]], dtype=np.complex)
print("comples array")
print(complexarr)
print("")
예제 #10
0
def mueve_col():
    import Numpy as np
    b = np.array([(34, 43, 73, 25, 10), (82, 22, 12, 14, 10),
                  (53, 94, 66, 84, 10), (35, 73, 24, 34, 10)])
    print(b)