0

Hello friends i have problem with sintaxis in numpy to create raw input , i not sure but i think i should make it float , if so please your help how to do it correct , the error i get is :

Traceback (most recent call last):
  File "eva.py", line 76, in <module>
    result = sigmoid(np.dot(single_point, weights) + bias)
TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

here is the script :

import numpy as np

feature_set = np.array([[0,1,0],[0,0,1],[1,0,0],[1,1,0],[1,1,1]])
labels = np.array([[1,0,0,1,1]])
labels = labels.reshape(5,1)
np.random.seed(42)
weights = np.random.rand(3,1)
bias = np.random.rand(1)
lr = 0.05

print 'data test chart '
print
print '        con=1    con=2    con=3    Result'
print
print ' A        0        1        0        1'
print ' B        0        0        1        0'
print ' C        1        0        0        0'
print ' D        1        1        0        1'
print ' E        1        1        1        1'
print
W1 = raw_input("    Con1 : ")
W2 = raw_input("    Con2 : ")
W3 = raw_input("    Con3 : ")

def sigmoid(x):
    return 1/(1+np.exp(-x))
def sigmoid_der(x):
    return sigmoid(x)*(1-sigmoid(x))
for epoch in range(20000):
    inputs = feature_set

    XW = np.dot(feature_set, weights) + bias
    z = sigmoid(XW)
    error = z - labels
    print(error.sum())
    dcost_dpred = error
    dpred_dz = sigmoid_der(z)
    z_delta = dcost_dpred * dpred_dz
    inputs = feature_set.T
    weights -= lr * np.dot(inputs, z_delta)
    for num in z_delta:
        bias -= lr * num

single_point = np.array([W1,W2,W3])
result = sigmoid(np.dot(single_point, weights) + bias)
print(result)

my problem in this line : single_point = np.array([W1,W2,W3]), its not want accept raw input , please your help .Thank you .

Eli Halych
  • 414
  • 4
  • 17
xanpx
  • 9
  • 5
  • `raw_input` returns a string if you want to work with numbers you need to convert that return value. If possible you should upgrade to Python 3.8+. – wwii Oct 03 '20 at 13:39
  • i try puthon 3 its give same eror : Cannot cast array data from dtype('float64') to dtype(' – xanpx Oct 03 '20 at 13:51
  • See the links above. Python 3 will not solve your problem - I was just commenting that you should upgrade if you don't have any constraints - the newer versions have some nice improvements and 2.x has been *retired*. – wwii Oct 03 '20 at 13:55
  • sorry links above not answer my question – xanpx Oct 03 '20 at 13:57
  • Change `W1 = raw_input(" Con1 : ")` to `W1 = float(raw_input(" Con1 : "))`, also for the other two. The Traceback you included says this line is causing the problem: `result = sigmoid(np.dot(single_point, weights) + bias)` not `single_point = np.array([W1,W2,W3])` – wwii Oct 03 '20 at 13:59
  • Perfect ! this work for me , thanks a lot friend ! Stay Home , Stay Safe – xanpx Oct 03 '20 at 14:13

0 Answers0