Monday, April 30, 2018

What is Sigmoid Curve Function ?

Sigmoid function

sigmoid function is a mathematical function having a characteristic "S"-shaped curve or sigmoid curve.

 Often, sigmoid function refers to the special case of the logistic function shown in the figure-1 and defined by the formula.

Monday, April 23, 2018

How to use Canvas in Tkinter?

Tkinter Canvas

The Canvas is a rectangular area intended for drawing pictures or other complex layouts.
You can place graphics, text, widgets or frames on a Canvas.

Syntax
Here is the simple syntax to create this widget

w= Canvas ( master, option=value, ... )

Friday, April 20, 2018

Tkinter Button in Python 3


Tkinter Button

The Button widget is used to add buttons in a Python application. These buttons can display text or images that convey the purpose of the buttons. You can attach a function or a method to a button which is called automatically when you click the button.

Syntax

w= Button ( master, option=value, ... )


Thursday, April 19, 2018

Tkinter Widgets in Python 3


Tkinter Widgets

Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI application. These controls are commonly called widgets.

There are currently 15 types of widgets in Tkinter. We present these widgets as well as a brief description in the following table-

Saturday, April 14, 2018

How to traverse the Node elements?

Traversing the Node Elements

We can traverse the elements of the node created above by creating a variable and assigning the first element to it.
 Then we use a while loop and nextval pointer to print out all the node elements. Note that we have one more additional data element and the nextval pointers are properly arranged to get the output as a days of a week in a proper sequence.

class daynames:
    def __init__(self, dataval=None):
        self.dataval = dataval
        self.nextval = None

e1 = daynames('Mon')
e2 = daynames('Wed')
e3 = daynames('Tue')
e4 = daynames('Thu')

e1.nextval = e3
e3.nextval = e2
e2.nextval = e4

thisvalue = e1

while thisvalue:
        print(thisvalue.dataval)
        thisvalue = thisvalue.nextval

When the above code is executed, it produces the following result.

Mon
Tue
Wed
Thu

The additional operations like insertion and deletion can be done by implementing appropriate methods by using this node containers in the general data structures like linked lists and trees. So we study them in the next chapters.


How to create a Python Node?


Creation of Nodes

The nodes are created by implementing a class which will hold the pointers along with the data element.

 In the below example we create a class named daynames to hold the name of the weekdays. The nextval pointer is initialized to null and three nodes and initialized with values as shown.

The nextval pointer of node e1 points to e3 while the nextval pointer of node e3 points to e2.

class daynames:
    def __init__(self, dataval=None):
        self.dataval = dataval
        self.nextval = None

e1 = daynames('Mon')
e2 = daynames('Wed')
e3 = daynames('Tue')

e1.nextval = e3
e3.nextval = e2





PYTHON - NODES

PYTHON - NODES


There are situations when the allocation of memory to store the data cannot be in a continuous block of memory. 
So we take help of pointers where the along with the data, the address of the next location of data element is also stored. 
So we know the address of the next data element from the values of current data element. 
In general such structures are known as pointers. But in Python we refer them as Nodes.

Nodes are the foundations on which various other data structures linked lists and trees can be handled in python.


Friday, April 13, 2018

Basic Tuples Operations


Basic Tuples Operations

Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string.

In fact, tuples respond to all of the general sequence operations we used on strings in the prior chapter −

Python Expression
Results
Description
len)
3
Length
 + 
Concatenation
 * 4
Repetition
3 in 
True
Membership
for x in : print (x),
1 2 3
Iteration





How to Delete Tuple Elements?


Delete Tuple Elements

Removing individual tuple elements is not possible. There is, of course, nothing wrong with putting together another tuple with the undesired elements discarded.
To explicitly remove an entire tuple, just use the del statement. For example −

#!/usr/bin/python3

tup = ('physics', 'chemistry', 1997, 2000);
print (tup);
del (tup);
print ("After deleting tup : ");
print (tup);

This produces the following result. Note an exception raised, this is because after del tup tuple does not exist any more −

('physics', 'chemistry', 1997, 2000)

After deleting tup :
Traceback (most recent call last):
   File "test.py", line 9, in <module>
      print tup;
NameError: name 'tup' is not defined





How to Update Tuples in Python ?


Updating Tuples

Tuples are immutable which means you cannot update or change the values of tuple elements. You are able to take portions of existing tuples to create new tuples as the following example demonstrates −

#!/usr/bin/python

tup1 = (12, 34.56);
tup2 = ('abc', 'xyz');

# Following action is not valid for tuples
# tup1[0] = 100;

# So let's create a new tuple as follows
tup3 = tup1 + tup2;
print (tup3);

When the above code is executed, it produces the following result −

(12, 34.56, 'abc', 'xyz')




How to Accese Values in Tuples?


Accessing Values in Tuples

To access values in tuple, use the square brackets for slicing along with the index or indices to obtain value available at that index. For example −

#!/usr/bin/python3

tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print ("tup1[0]: ", tup1[0]);
print ("tup2[1:5]: ", tup2[1:5]);

When the above code is executed, it produces the following result 
tup1[0]:  physics
tup2[1:5]:  [2, 3, 4, 5]