Question

In: Computer Science

I need the following problem to be coded in python without using Numpy: Given input features...

I need the following problem to be coded in python without using Numpy:

Given input features x1​, x2​,..., xi​ and corresponding weights w0​, w1​, w2​,...wi​. Write a function, called 'Perceptron', that returns the output value yi. For your function, use the following perceptron activation function:

g(X,W)={1 if wTx>0;0 otherwise}

The inputs X and W will be arrays of the input feature and weight values, respectively. All values will be integers. Your function will return gp​(X,W), which is a single integer value:

def perceptron(X, W):

Solutions

Expert Solution

Code is very simple. We have to first import module array in python and then we will perform the task.

Below is the screenshot of python code.

Below is the screenshot of output

Below is the same code in text format.

import array

def perceptron(X, W):
   result = 0     #This will store the value of W^T*X
   for i in range(0,len(X)):
       result =result + X[i]*W[i]    #storing value of W^T*X
   if result > 0:       #if result > 0 then return 1 else return 0
       return 1
   else :
       return 0


X=array.array('i',[3,4,-5,3]) #defining array X of type inereger

W=array.array('i',[1,1,3,-3]) #defining array W of type inereger

Y = perceptron(X, W)   #storing the output in Y

print("The result is " + str(Y))   #printing the result

Please comment for any clarification.


Related Solutions

Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
need to write program on python, without using any other libraries like panda, numpy, etc. here...
need to write program on python, without using any other libraries like panda, numpy, etc. here is google link on csv file https://drive.google.com/file/d/1O3cC9JAPVkXSrddTR6RocpSV8NMHrmRx/view?usp=sharing There is a csv file, which is exel file, very big and what program should do: - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values (should search in all rows) - Replace the empty values by 'NA' for strings,...
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x...
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep...
Using Python coding language (with or without Pandas and/or NumPy), 1. Can you define function sleep to tell whether the participant are of the ages through 18 to 60 and sleep less than 6 hours per day? 2. Develop codes to check whether the sleep function you defined can make correct judgement. Make sure you write comments or create informative vairable name so that I can understand how you check the sleep function. (Hints: You can create toy data/dataframe to...
In Python, I have a turtle that is already coded to move in correlation with the...
In Python, I have a turtle that is already coded to move in correlation with the keys I set (I can control the turtle). I need to put a second turtle in that moves WHILE the first turtle is moving and being controlled. The second turtle needs to do the following while the first turtle is still listening and being controlled: -It needs to begin facing a random direction -It needs to move at a speed of .5 the entire...
i need the pseudocode and python program for the following problem. Besides the user entering the...
i need the pseudocode and python program for the following problem. Besides the user entering the number of books purchased this order, they are asked for the number of points earned for the year before this order and the number of books ordered this year before this order. There are bonus points awarded based on the number of books previously ordered and number ordered now. These points should be added to the variable points: Current order: 0 Previous Orders >...
I need to write an interpreter for arithmetic expressions in Python. This program receives an input...
I need to write an interpreter for arithmetic expressions in Python. This program receives an input string with an arithmetic expression and does: 1. prints a ">>>" as if it was a terminal 2. lets us allocate a variable to a a numeric value (as "a = 3") then it stores {'a':3} to a dictionary memory 3. whenever it receives an expression or input, transform it to postfix notation and print it (even when allocating variables) 4. it is able...
Write a python code that calculates π using numpy rand function.
Write a python code that calculates π using numpy rand function.
****NEED CODED IN C++, READ THE INSTRUCTIONS CAREFULLY AND PAY ATTENTION TO THE INPUT FILE, IT...
****NEED CODED IN C++, READ THE INSTRUCTIONS CAREFULLY AND PAY ATTENTION TO THE INPUT FILE, IT IS REQUIRED FOR USE IN THE PROBLEM**** You are to generate a list of customers to serve based on the customer’s priority, i.e. create a priority queue/list for a local company. The company has been receiving request and the request are recorded in a file, in the order the request was made. The company processes each user based on their priority, the highest priority...
This question need to be solved using java coading :- I. Input All input data are...
This question need to be solved using java coading :- I. Input All input data are from a file "in.dat". The file contains a sequence of infix form expressions, one per line. The character '$' is an end mark. For example, the following file has four infix form expressions: 1 + 2 * 3 ^ ! ( 4 == 5 ) $ 3 * ( 6 - 4 * 5 + 1) + 2 ^ 2 ^ 3 $ 77...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT