Named-Arguments-In-Format

Fri 14 November 2025

title: "Named Arguments in Format" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


print("{greeting!r:20}".format(greeting="Hello"))
'Hello'
print("{one} {two!r}".format(one="ten", two="twenty"))
ten 'twenty'


Score: 0

Category: basics

Read More

Named-Colors

Fri 14 November 2025
import six

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors


colors_ = list(six.iteritems(colors.cnames))

# Add the single letter colors.
for name, rgb in six.iteritems(colors.ColorConverter.colors):
    hex_ = colors.rgb2hex(rgb)
    colors_.append((name, hex_))

# Transform to hex color values.
hex_ = [color …

Category: barchart

Read More

Negative Lookahead

Fri 14 November 2025

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


import re
test = [ ('i sure like eating pie, but i love donuts', True),
         ('i sure like eating pie, but i hate donuts', True),
         ('i sure hate eating pie, but i like donuts', False) ]
rx = re.compile …

Category: regex

Read More

New-Axis

Fri 14 November 2025

import numpy as np

x1 = np.arange(1,10).reshape(3,3)
print(x1.shape)

x1_new = x1[:,np.newaxis]
print(x1_new.shape)
(3, 3)
(3, 1, 3)


Score: 0

Category: array

Read More

Np-Full

Fri 14 November 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]'
print(pyu.ps2("pandas"))
pandas==2.2.3

from functools import reduce
product = reduce((lambda x, y: x * y), [1, 2 …

Category: pandas

Read More

Nth-Row

Fri 14 November 2025

title: "Get Nth row" author: "Rj" date: 2019-04-22 description: "-" type: technical_note draft: false


import numpy as np
import pandas as pd
df = pd.read_csv('data1.csv')
df
capacity score length
0 1 …

Category: data-wrangling

Read More

Numba Benchmark

Fri 14 November 2025

title: "Numba Benchmark" author: "Raja CSP Raman" date: 2019-05-07 description: "-" type: technical_note draft: false


from numba import jit
import numpy as np
import time
x = np.arange(100).reshape(10, 10)

@jit(nopython=True)
def go_fast(a): # Function is compiled and runs in machine code
    trace = 0
    for i in …

Category: numba

Read More

Number-Check

Fri 14 November 2025

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


import re
pattern = re.compile("^([0-9]+)+$")

content  = "s23434"

if(pattern.match(content)):
    print(pattern.match(content).pos)
else:
    print('not matched')
not matched
content  = "23434"

if(pattern.match(content)):
    print('matched at : ', pattern.match(content).pos …

Category: regex

Read More

Number Counter

Fri 14 November 2025

title: "Number Counter" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false source: https://www.accelebrate.com/blog/using-defaultdict-python/


from collections import defaultdict
counter = defaultdict(int)
content = "one 2 1 three 4 2 1 7 6 six 8 9 8"
content
'one 2 1 three 4 2 1 …

Category: basics

Read More

Numpy-2-Tensor

Fri 14 November 2025

title: "Numpy 2 Tensor" author: "Raja CSP Raman" date: 2019-05-07 description: "-" type: technical_note draft: false


import tensorflow as tf
import numpy as np
import os

# Just disables the warning, doesn't enable AVX/FMA
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
a = np.zeros((3, 3))
ta = tf.convert_to_tensor(a)

with tf.Session …

Category: tensorflow-work

Read More
Page 117 of 146

« Prev Next »