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)max_fast(a, b)min_fast(a, b)
Useful functions
fast_sample(objects, probs)-- returns 1 random object fromobjectswithprobsprobabilities. It's faster thannp.random.choice(objects, 1, probs)(example)randomTrue(prob = 0.5)-- returnsTruewith probabilityprob, otherwiseFalse
Useful for debug:
set_trace()-- like breakpointdebug(function, *args, **kwargs)-- for debugfunctionfunction with those arguments
R-like functions
For arrays there are several R-like functions:
ifelse— just wrapper ofnumpy.wherenrow— 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 functionFUNto dimension ofarr2Darray (for rows ifMARGIN == 1and columns ifMARGIN == 2)lapply— applies functionfuncfor each element inarray(array/list or something else)sapply— likelapplybut returns numpy arraysample— it isnp.random.choicebutreplace = Falseby defaultsample_int— sample numbers from0ton-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]
Functions without category
time_to_seconds(days = 0, hours = 0, minutes = 0, seconds = 5)-- converts time to seconds
Metadata
Release files for truefalsepython 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| truefalsepython-0.2.0.tar.gz | 5.7 kB | Without provenance | Details for truefalsepython-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| truefalsepython-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for truefalsepython-0.2.0-py3-none-any.whl |
Total release size: 12.3 kB
Release files / truefalsepython-0.2.0.tar.gz
| Download URL | truefalsepython-0.2.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72fbd8843e4548dd722df8952580b20109f52dcb1fb004256e6fc0c1b6658f82
|
|
BLAKE2b-256 checksum How to use checksums |
664b11940fcf5af0fb8197bb2698dbf0f7ec71696be460fb7b005491cfb8b5a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
|
Release files / truefalsepython-0.2.0-py3-none-any.whl
| Download URL | truefalsepython-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ffe643bd1cf1482848de8347cd0df2ab3b2b3ef103dc2b67129020b7ca67de4d
|
|
BLAKE2b-256 checksum How to use checksums |
40192b6a0e04c631656d2ac045e7d35748e6af955d4c06dc5924072d52453b7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3
|
Security for truefalsepython 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.