PyPI package with some better syntax tools for python
Project description
true-false-python
PyPI package with some better syntax tools for python
pip install truefalsepython
Logical tools
For True
and False
values there are equal constants (like it is in C-like languages or R) TRUE, T, true
and FALSE, F, false
; for None
there is NULL
constant:
from truefalsepython import TRUE, FALSE, T, F, true, false, NULL
print(True == T) # True
print(True == TRUE) # True
print(True == true) # True
print(False == F) # True
print(False == FALSE) # True
print(False == false) # True
print(NULL) # None
Little functions
is_odd(number)
is_even(number)
is_number(object)
R-like functions
For arrays there are several R-like functions:
nrow
— returns number of rowsncol
— returns number of columnscolMeans
— returns average for each columnrowMeans
— returns average for each rowcolSums
— returns sums for each columnrowSums
— returns sums for each rowapply
— applies functionFUN
to dimension ofarr2D
array (for rows ifMARGIN == 1
and columns ifMARGIN == 2
)lapply
— applies functionfunc
for each element inarray
(array/list or something else)sapply
— likelapply
but returns numpy arraysample
— it isnp.random.choice
butreplace = False
by defaultsample_int
— sample numbers from0
ton-1
Example of usage:
import numpy as np
from truefalsepython import nrow, ncol, colMeans, rowMeans, colSums, rowSums, apply, lapply, sapply, sample, sample_int
np.random.seed(1)
# some 2D array
random_matrix = np.random.randint(8, size = (5, 3))
# how to get rows and cols counts
print(nrow(random_matrix)) # 5
print(ncol(random_matrix)) # 3
# operations for each row/column
print(rowMeans(random_matrix))
# [4. 2.66666667 5. 0.33333333 5.33333333]
print(colMeans(random_matrix))
# [2.4 4.4 3.6]
print(rowSums(random_matrix))
# [12 8 15 1 16]
print(colSums(random_matrix))
# [12 22 18]
# apply function (MARGIN is 1 for rows and 2 for columns)
print(apply(random_matrix, MARGIN = 1, FUN = np.min))
# [3 0 3 0 4]
# as u can see, it's not necessary to use FUN returns only 1 number by vector
print(apply(random_matrix, MARGIN = 2, FUN = np.sqrt))
#[[2.23606798 0. 1.73205081 0. 2. ]
# [1.73205081 2.64575131 2.23606798 0. 2.64575131]
# [2. 1. 2.64575131 1. 2.23606798]]
some_arr = np.array([1, 2, 3, 5, 4, 3, 2])
# returns list
print(lapply(some_arr, lambda x: -x))
# [-1, -2, -3, -5, -4, -3, -2]
# returns numpy array
print(sapply(some_arr, lambda x: -x))
# [-1 -2 -3 -5 -4 -3 -2]
# like np.random.choice but replace = False by default
print(sample(some_arr, 4))
# [5 3 2 1]
# sample numbers from 0 to n-1
print(sample_int(n = 100, size = 10))
# [69 46 58 12 73 98 31 53 65 96]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
truefalsepython-0.1.1.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for truefalsepython-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f4909968cabcdc5fe6d9db7af559a7f00324da35d15dad166a596dfad803443 |
|
MD5 | 7ee8e8da9adabdfac3ff8a538f3e0b7a |
|
BLAKE2b-256 | 3f365d80257d753041d2dc4ae322ea53905fe69480aead15664451db9ea93447 |