Counter-Simple

Sat 17 May 2025

title: "Counter Simple" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


from collections import Counter
a = Counter("Hello there, How are you")
a
Counter({' ': 4,
         ',': 1,
         'H': 2,
         'a': 1,
         'e': 4,
         'h': 1,
         'l': 2,
         'o': 3,
         'r': 2,
         't': 1,
         'u': 1,
         'w': 1,
         'y …

Category: basics

Read More

Cricket Match 2 Over

Sat 17 May 2025

title: "Cricket Match 2 Overs" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


import time
import random as rd
team_1_score = 0
team_2_score = 0
def play_over(over, t_score):

    print('Over ', over)

    for x in range(6):

        score = rd.randint(0, 6)
        t_score += score
        print('Ball ', (x+1), score …

Category: basics

Read More

Current-Directory

Sat 17 May 2025

title: "Current Directory" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


import os
dirpath = os.getcwd()
print("current directory is : " + dirpath)
current directory is : /Users/rajacsp/projects/mlnotes/content/python/basics
foldername = os.path.basename(dirpath)
print("Directory name is : " + foldername)
Directory name is : basics
scriptpath = os …

Category: basics

Read More

Data Array Simple

Sat 17 May 2025

title: "Data Array Simple" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import xarray as xr
import numpy as np
import pandas as pd
data = np.random.rand(4, 3)

locs = ['TO', 'ML', 'WL']

times = pd.date_range('2000-01-01', periods=4)
abc = xr.DataArray(data, coords=[times, locs], dims=['time …

Category: basics

Read More

Date-Maker-1

Sat 17 May 2025
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml312-2024; pyv: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:27:36) [GCC 11.2.0]'
# will be used in MyWalks
# https://docs.google.com/spreadsheets/d/1WZOx71Pg7Id_dd6wLRDQbmS8ZDaRdkMQIwltM6vFTX8/edit?gid=0#gid=0
from datetime import datetime …

Category: basics

Read More

Date-Util

Sat 17 May 2025

title: "Date Util" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import datetime
now = datetime.datetime.now()
print(now.year)
2019
print (now.strftime("%y"))
19
print (now.strftime("%d"))
21
print (now.strftime("%m"))
04
print(datetime.datetime.today())
2019-04-21 18:34:57.280555
cur_date = datetime …

Category: basics

Read More

Decision-Tree-Prediction

Sat 17 May 2025

title: "Decision Tree Prediction" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


from sklearn import tree
X = [[0, 0], [2, 2]]
y = [0.5, 2.5]
clf = tree.DecisionTreeRegressor()
clf = clf.fit(X, y)
predicted = clf.predict([[1, 1]])
print(predicted)
[0.5]


Score: 5

Category: basics

Read More

Decision-Tree-Regression

Sat 17 May 2025

title: "Decision Tree Regression" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


import numpy as np
from sklearn.tree import DecisionTreeRegressor
import matplotlib.pyplot as plt
# Create a random dataset
rng = np.random.RandomState(1)
X = np.sort(5 * rng.rand(80, 1), axis=0)
y = np …

Category: basics

Read More

Decorator

Sat 17 May 2025

title: "Decorator" author: "Raja CSP Raman" date: 2019-04-20 description: "-" type: technical_note draft: false


def rangetest(*argchecks):                  # validate positional arg ranges
    def onDecorator(func):
        def onCall(*args):
            print('argchecks : '+str(argchecks))
            for (ix, low, high) in argchecks:
                print('ix : '+str(ix))
                if args[ix] < low or args[ix] > high:
                    errmsg = 'Argument …

Category: basics

Read More

Decorator-Sample-2

Sat 17 May 2025

title: "Decorator Sample 2" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


class my_decorator(object):

    def __init__(self, f):
        print("inside my_decorator.__init__()")
        f() # Prove that function definition has completed

    def __call__(self):
        print("inside my_decorator.__call__()")
@my_decorator
def aFunction():
    print("inside aFunction()")
inside my_decorator.__init__()
inside aFunction()
print …

Category: basics

Read More
Page 3 of 17

« Prev Next »