Fix all errors mentioned in pre-commit run (#2512)

* Fix all errors mentioned in pre-commit run:

- Fix end of file
- Remove trailing whitespace
- Fix files with black
- Fix imports with isort

* Fix errors
This commit is contained in:
Dhruv 2020-09-30 14:08:00 +05:30 committed by GitHub
parent e6e2dc69d5
commit 0a42ae9095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 86 additions and 85 deletions

2
.github/stale.yml vendored
View File

@ -16,5 +16,5 @@ markComment: >
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
Please reopen this issue once you commit the changes requested or
Please reopen this issue once you commit the changes requested or
make improvements on the code. Thank you for your contributions.

View File

@ -19,7 +19,7 @@ jobs:
black .
isort --profile black .
git config --global user.name github-actions
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git commit -am "fixup! Format Python code with psf/black push"
git push --force origin HEAD:$GITHUB_REF

View File

@ -9,7 +9,7 @@ jobs:
include:
- name: Build
before_script:
- black --check . || true
- black --check . || true
- flake8 --ignore=E203,W503 --max-complexity=25 --max-line-length=88 --statistics --count .
- scripts/validate_filenames.py # no uppercase, no spaces, in a directory
- pip install -r requirements.txt # fast fail on black, flake8, validate_filenames

View File

@ -1,5 +1,5 @@
# The Algorithms - Python
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Python)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/Python)
[![Gitter chat](https://img.shields.io/badge/Chat-Gitter-ff69b4.svg?label=Chat&logo=gitter&style=flat-square)](https://gitter.im/TheAlgorithms) 
[![Build Status](https://img.shields.io/travis/TheAlgorithms/Python.svg?label=Travis%20CI&logo=travis&style=flat-square)](https://travis-ci.com/TheAlgorithms/Python) 
[![LGTM](https://img.shields.io/lgtm/alerts/github/TheAlgorithms/Python.svg?label=LGTM&logo=LGTM&style=flat-square)](https://lgtm.com/projects/g/TheAlgorithms/Python/alerts) 

View File

@ -3,9 +3,9 @@ Braidwood, Illustrated by Susan T. Richert
This eBook is for the use of anyone anywhere in the United States and most
other parts of the world at no cost and with almost no restrictions
other parts of the world at no cost and with almost no restrictions
whatsoever. You may copy it, give it away or re-use it under the terms of
the Project Gutenberg License included with this eBook or online at
the Project Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United States, you'll have
to check the laws of the country where you are located before using this ebook.
@ -7109,9 +7109,9 @@ and permanent future for Project Gutenberg-tm and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help, see
Sections 3 and 4 and the Foundation information page at
www.gutenberg.org
www.gutenberg.org
Section 3. Information about the Project Gutenberg Literary
Section 3. Information about the Project Gutenberg Literary
Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non profit

View File

@ -2,7 +2,7 @@
Computer vision is a field of computer science that works on enabling computers to see,
identify and process images in the same way that human vision does, and then provide appropriate output.
It is like imparting human intelligence and instincts to a computer.
It is like imparting human intelligence and instincts to a computer.
Image processing and computer vision and little different from each other.Image processing means applying some algorithms for transforming image from one form to other like smoothing,contrasting, stretching etc
While in computer vision comes from modelling image processing using the techniques of machine learning.Computer vision applies machine learning to recognize patterns for interpretation of images.
While in computer vision comes from modelling image processing using the techniques of machine learning.Computer vision applies machine learning to recognize patterns for interpretation of images.
Much like the process of visual reasoning of human vision

View File

@ -3,14 +3,16 @@ render 3d points for 2d surfaces.
"""
from __future__ import annotations
import math
__version__ = "2020.9.26"
__author__ = "xcodz-dot, cclaus, dhruvmanila"
def convert_to_2d(x: float, y: float, z: float, scale: float,
distance: float) -> tuple[float, float]:
def convert_to_2d(
x: float, y: float, z: float, scale: float, distance: float
) -> tuple[float, float]:
"""
Converts 3d point to a 2d drawable point
@ -26,15 +28,17 @@ def convert_to_2d(x: float, y: float, z: float, scale: float,
TypeError: Input values must either be float or int: ['1', 2, 3, 10, 10]
"""
if not all(isinstance(val, (float, int)) for val in locals().values()):
raise TypeError("Input values must either be float or int: "
f"{list(locals().values())}")
raise TypeError(
"Input values must either be float or int: " f"{list(locals().values())}"
)
projected_x = ((x * distance) / (z + distance)) * scale
projected_y = ((y * distance) / (z + distance)) * scale
return projected_x, projected_y
def rotate(x: float, y: float, z: float, axis: str,
angle: float) -> tuple[float, float, float]:
def rotate(
x: float, y: float, z: float, axis: str, angle: float
) -> tuple[float, float, float]:
"""
rotate a point around a certain axis with a certain angle
angle can be any integer between 1, 360 and axis can be any one of
@ -67,18 +71,20 @@ def rotate(x: float, y: float, z: float, axis: str,
input_variables = locals()
del input_variables["axis"]
if not all(isinstance(val, (float, int)) for val in input_variables.values()):
raise TypeError("Input values except axis must either be float or int: "
f"{list(input_variables.values())}")
raise TypeError(
"Input values except axis must either be float or int: "
f"{list(input_variables.values())}"
)
angle = (angle % 360) / 450 * 180 / math.pi
if axis == 'z':
if axis == "z":
new_x = x * math.cos(angle) - y * math.sin(angle)
new_y = y * math.cos(angle) + x * math.sin(angle)
new_z = z
elif axis == 'x':
elif axis == "x":
new_y = y * math.cos(angle) - z * math.sin(angle)
new_z = z * math.cos(angle) + y * math.sin(angle)
new_x = x
elif axis == 'y':
elif axis == "y":
new_x = x * math.cos(angle) - z * math.sin(angle)
new_z = z * math.cos(angle) + x * math.sin(angle)
new_y = y

View File

@ -1,35 +1,35 @@
# Linear algebra library for Python
# Linear algebra library for Python
This module contains classes and functions for doing linear algebra.
This module contains classes and functions for doing linear algebra.
---
## Overview
## Overview
### class Vector
### class Vector
-
- This class represents a vector of arbitrary size and related operations.
- This class represents a vector of arbitrary size and related operations.
**Overview about the methods:**
- constructor(components : list) : init the vector
- set(components : list) : changes the vector components.
- \_\_str\_\_() : toString method
- component(i : int): gets the i-th component (start by 0)
- \_\_len\_\_() : gets the size / length of the vector (number of components)
- euclidLength() : returns the eulidean length of the vector.
- operator + : vector addition
- operator - : vector subtraction
- operator * : scalar multiplication and dot product
- copy() : copies this vector and returns it.
- changeComponent(pos,value) : changes the specified component.
**Overview about the methods:**
- function zeroVector(dimension)
- returns a zero vector of 'dimension'
- function unitBasisVector(dimension,pos)
- returns a unit basis vector with a One at index 'pos' (indexing at 0)
- function axpy(scalar,vector1,vector2)
- computes the axpy operation
- constructor(components : list) : init the vector
- set(components : list) : changes the vector components.
- \_\_str\_\_() : toString method
- component(i : int): gets the i-th component (start by 0)
- \_\_len\_\_() : gets the size / length of the vector (number of components)
- euclidLength() : returns the eulidean length of the vector.
- operator + : vector addition
- operator - : vector subtraction
- operator * : scalar multiplication and dot product
- copy() : copies this vector and returns it.
- changeComponent(pos,value) : changes the specified component.
- function zeroVector(dimension)
- returns a zero vector of 'dimension'
- function unitBasisVector(dimension,pos)
- returns a unit basis vector with a One at index 'pos' (indexing at 0)
- function axpy(scalar,vector1,vector2)
- computes the axpy operation
- function randomVector(N,a,b)
- returns a random vector of size N, with random integer components between 'a' and 'b'.
@ -37,39 +37,39 @@ This module contains classes and functions for doing linear algebra.
-
- This class represents a matrix of arbitrary size and operations on it.
**Overview about the methods:**
- \_\_str\_\_() : returns a string representation
- operator * : implements the matrix vector multiplication
implements the matrix-scalar multiplication.
- changeComponent(x,y,value) : changes the specified component.
- component(x,y) : returns the specified component.
- width() : returns the width of the matrix
- height() : returns the height of the matrix
- determinate() : returns the determinate of the matrix if it is square
- operator + : implements the matrix-addition.
- operator - _ implements the matrix-subtraction
**Overview about the methods:**
- function squareZeroMatrix(N)
- returns a square zero-matrix of dimension NxN
- function randomMatrix(W,H,a,b)
- returns a random matrix WxH with integer components between 'a' and 'b'
- \_\_str\_\_() : returns a string representation
- operator * : implements the matrix vector multiplication
implements the matrix-scalar multiplication.
- changeComponent(x,y,value) : changes the specified component.
- component(x,y) : returns the specified component.
- width() : returns the width of the matrix
- height() : returns the height of the matrix
- determinate() : returns the determinate of the matrix if it is square
- operator + : implements the matrix-addition.
- operator - _ implements the matrix-subtraction
- function squareZeroMatrix(N)
- returns a square zero-matrix of dimension NxN
- function randomMatrix(W,H,a,b)
- returns a random matrix WxH with integer components between 'a' and 'b'
---
## Documentation
## Documentation
This module uses docstrings to enable the use of Python's in-built `help(...)` function.
For instance, try `help(Vector)`, `help(unitBasisVector)`, and `help(CLASSNAME.METHODNAME)`.
---
## Usage
## Usage
Import the module `lib.py` from the **src** directory into your project.
Alternatively, you can directly use the Python bytecode file `lib.pyc`.
Alternatively, you can directly use the Python bytecode file `lib.pyc`.
---
## Tests
## Tests
`src/tests.py` contains Python unit tests which can be run with `python3 -m unittest -v`.

View File

@ -3,11 +3,11 @@
predict house price.
"""
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.datasets import load_boston
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.model_selection import train_test_split
@ -42,10 +42,7 @@ def main():
training_score = model.score(X_train, y_train).round(3)
test_score = model.score(X_test, y_test).round(3)
print("Training score of GradientBoosting is :", training_score)
print(
"The test score of GradientBoosting is :",
test_score
)
print("The test score of GradientBoosting is :", test_score)
# Let us evaluation the model by finding the errors
y_pred = model.predict(X_test)
@ -57,8 +54,7 @@ def main():
# So let's run the model against the test data
fig, ax = plt.subplots()
ax.scatter(y_test, y_pred, edgecolors=(0, 0, 0))
ax.plot([y_test.min(), y_test.max()],
[y_test.min(), y_test.max()], "k--", lw=4)
ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], "k--", lw=4)
ax.set_xlabel("Actual")
ax.set_ylabel("Predicted")
ax.set_title("Truth vs Predicted")

View File

@ -4,10 +4,10 @@
Sieve of Eratosthenes
Input : n =10
Output: 2 3 5 7
Output: 2 3 5 7
Input : n = 20
Output: 2 3 5 7 11 13 17 19
Output: 2 3 5 7 11 13 17 19
you can read in detail about this at
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

View File

@ -17,4 +17,4 @@
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

View File

@ -997,4 +997,4 @@
672276,515708
325361,545187
172115,573985
13846,725685
13846,725685

View File

@ -2899,4 +2899,4 @@
725,
"4598797036650685"
]
]
]

View File

@ -13,9 +13,9 @@ The array elements are taken from a Standard Normal Distribution , having mean =
```python
>>> import numpy as np
>>> import numpy as np
>>> from tempfile import TemporaryFile
>>> outfile = TemporaryFile()
>>> outfile = TemporaryFile()
>>> p = 100 # 100 elements are to be sorted
>>> mu, sigma = 0, 1 # mean and standard deviation
>>> X = np.random.normal(mu, sigma, p)
@ -34,7 +34,7 @@ The array elements are taken from a Standard Normal Distribution , having mean =
>>> s = np.random.normal(mu, sigma, p)
>>> count, bins, ignored = plt.hist(s, 30, normed=True)
>>> plt.plot(bins , 1/(sigma * np.sqrt(2 * np.pi)) *np.exp( - (bins - mu)**2 / (2 * sigma**2) ),linewidth=2, color='r')
>>> plt.show()
>>> plt.show()
```
@ -52,15 +52,15 @@ The array elements are taken from a Standard Normal Distribution , having mean =
--
## Plotting the function for Checking 'The Number of Comparisons' taking place between Normal Distribution QuickSort and Ordinary QuickSort
## Plotting the function for Checking 'The Number of Comparisons' taking place between Normal Distribution QuickSort and Ordinary QuickSort
```python
>>>import matplotlib.pyplot as plt
# Normal Disrtibution QuickSort is red
>>> plt.plot([1,2,4,16,32,64,128,256,512,1024,2048],[1,1,6,15,43,136,340,800,2156,6821,16325],linewidth=2, color='r')
#Ordinary QuickSort is green
>>> plt.plot([1,2,4,16,32,64,128,256,512,1024,2048],[1,1,4,16,67,122,362,949,2131,5086,12866],linewidth=2, color='g')
@ -73,4 +73,3 @@ The array elements are taken from a Standard Normal Distribution , having mean =
------------------