Python Code Snippets for Data Science and AI

# **Program 1:

NumPy

Array Operations**
import numpy as np
arr=np.Array([[1,2,3],[4,5,6],[7,8,9]])
print(“Sum of all columns:”,np.
sum(arr,axis=0))
print(“Product of all rows:”,np.Prod(arr,axis=1))
print(“Last two rows and columns:\n”,arr[1:,1:])
arr2=np.Array([[9,8,7],[6,5,4],[3,2,1]])
print(“Element-wise addition:\n”,arr+arr2)
.
.

# **Program 2: Vowel Frequency in Each Word**
sentence=input(“Enter a sentence in lowercase: “)
vowels=’aeiou’
for w in sentence.Split():
    print(f”{w}: {sum(w.Count(v) for v in

Read More

Java Implementation of DSS Signing and Cipher Cryptanalysis

Digital Signature Standard (DSS) Client Implementation

This Java class, DssClient, demonstrates the generation of a Digital Signature Standard (DSS) signature and subsequent transmission of the parameters to a verification server via a socket connection.

1.1. DssClient Class Structure and Signature Generation

The dssSign method calculates the signature components r and s, along with the public key y, based on input parameters (primes p, q, generator g, private key x, message hash H(m), and random nonce

Read More

Artificial Intelligence Search Algorithms and Agent Fundamentals

AI Agents and Architecture

Agents perceive their environment using sensors and act rationally upon that environment using effectors.

Agent Architecture

Agent → Actions (with effectors) → Environment → Percepts → Agent

Key Agent Features

  • Situatness: The agent’s direct connection to its environment through percepts and effectors.
  • Autonomy: The agent acts without intervention by humans or other agents. (Preprogramming does not count.)
  • Adaptivity: The ability to react flexibly to changes in its environment.
Read More

Wireless Communication Protocols and Mobile Network Architecture

Wireless Application Protocol (WAP) Fundamentals

WAP (Wireless Application Protocol) is a set of protocols designed for wireless devices (like mobile phones and PDAs) to access internet services. It uses a client-server model, with the mobile device acting as the client and a WAP gateway/web server as the server. WAP optimizes content for low bandwidth, small screens, and limited processing power.

WAP Protocol Stack Layers

The WAP model is structured into several distinct layers:

  • Application Layer:
Read More

Digital Modulation Techniques in Python: Pulse Shaping and QPSK

import numpy as np

T = 1 #time period

Fs = 100 #sampling frequency

t = np.
arange(-3*T, 3*T, 1/Fs)

g = lambda t: np.Sinc(t) * np.Cos(np.Pi*0.5*t) / (1-(2*0.5*t)**2) #Defining a lambda function g(t) that represents a raised cosine filter with a roll-off factor of 0.5.

plt.
Figure(figsize=(8,3))

plt.Plot(t, g(t))

binary_sequence = np.Array(np.Random.Randint(2,size=50))

d = 2 * np.Array(binary_sequence) – 1 #making the binary sequence NRZ

def get_signal(d): #to get transmitted signal

    t = np.Arange(-2*T,

Read More

Implementing Core Machine Learning Algorithms in Python

1. Perceptron Algorithm Implementation

The Perceptron is a foundational linear classification algorithm. This implementation uses NumPy for efficient vector operations.

Perceptron Class Definition

import numpy as np, random

class Perceptron:
    def __init__(self, eta=0.01, n_iter=50, random_state=1):
        self.eta, self.n_iter, self.random_state = eta, n_iter, random_state

    def fit(self, x, y):
        rgen = np.random.RandomState(self.random_state)
        self.w_ = rgen.normal(0, 0.01, 1 
Read More