From e29f3a6acc422f9a3da0e7ad82698b19a823edce Mon Sep 17 00:00:00 2001 From: moT01 <20648924+moT01@users.noreply.github.com> Date: Tue, 29 Sep 2020 12:25:21 -0500 Subject: [PATCH] init --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ main.py | 8 ++++++++ mean_var_std.py | 8 ++++++++ poetry.lock | 14 ++++++++++++++ pyproject.toml | 15 +++++++++++++++ test_module.py | 21 +++++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 README.md create mode 100644 main.py create mode 100644 mean_var_std.py create mode 100644 poetry.lock create mode 100644 pyproject.toml create mode 100644 test_module.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..5bc5fdd --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +### Assignment + +Create a function named `calculate()` in `mean_var_std.py` that uses Numpy to output the mean, variance, standard deviation, max, min, and sum of the rows, columns, and elements in a 3 x 3 matrix. + +The input of the function should be a list containing 9 digits. The function should convert the list into a 3 x 3 Numpy array, and then return a dictionary containing the mean, variance, standard deviation, max, min, and sum along both axes and for the flattened matrix. + +The returned dictionary should follow this format: +```py +{ + 'mean': [axis1, axis2, flattened], + 'variance': [axis1, axis2, flattened], + 'standard deviation': [axis1, axis2, flattened], + 'max': [axis1, axis2, flattened], + 'min': [axis1, axis2, flattened], + 'sum': [axis1, axis2, flattened] +} +``` + +If a list containing less than 9 elements is passed into the function, it should raise a `ValueError` exception with the message: "List must contain nine numbers." The values in the returned dictionary should be lists and not Numpy arrays. + +For example, `calculate([0,1,2,3,4,5,6,7,8])` should return: +```py +{ + 'mean': [[3.0, 4.0, 5.0], [1.0, 4.0, 7.0], 4.0], + 'variance': [[6.0, 6.0, 6.0], [0.6666666666666666, 0.6666666666666666, 0.6666666666666666], 6.666666666666667], + 'standard deviation': [[2.449489742783178, 2.449489742783178, 2.449489742783178], [0.816496580927726, 0.816496580927726, 0.816496580927726], 2.581988897471611], + 'max': [[6, 7, 8], [2, 5, 8], 8], + 'min': [[0, 1, 2], [0, 3, 6], 0], + 'sum': [[9, 12, 15], [3, 12, 21], 36]} +} +``` + +The unit tests for this project are in `test_module.py`. + +### Development + +For development, you can use `main.py` to test your `calculate()` function. Click the "run" button and `main.py` will run. + +### Testing + +We imported the tests from `test_module.py` to `main.py` for your convenience. The tests will run automatically whenever you hit the "run" button. + +### Submitting + +Copy your project's URL and submit it to freeCodeCamp. diff --git a/main.py b/main.py new file mode 100644 index 0000000..cbe86e5 --- /dev/null +++ b/main.py @@ -0,0 +1,8 @@ +# This entrypoint file to be used in development. Start by reading README.md +import mean_var_std +from unittest import main + +print(mean_var_std.calculate([0,1,2,3,4,5,6,7,8])) + +# Run unit tests automatically +main(module='test_module', exit=False) \ No newline at end of file diff --git a/mean_var_std.py b/mean_var_std.py new file mode 100644 index 0000000..f9d4d6d --- /dev/null +++ b/mean_var_std.py @@ -0,0 +1,8 @@ +import numpy as np + +def calculate(list): + + + + + return calculations \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..9315f02 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,14 @@ +[[package]] +category = "main" +description = "NumPy is the fundamental package for array computing with Python." +name = "numpy" +optional = false +python-versions = ">=3.5" +version = "1.18.5" + +[metadata] +content-hash = "362a4cdb0a177f527c73204355c2f4424c04716ca4bf001d1ab0c27db017feef" +python-versions = "^3.8" + +[metadata.hashes] +numpy = ["0172304e7d8d40e9e49553901903dc5f5a49a703363ed756796f5808a06fc233", "34e96e9dae65c4839bd80012023aadd6ee2ccb73ce7fdf3074c62f301e63120b", "3676abe3d621fc467c4c1469ee11e395c82b2d6b5463a9454e37fe9da07cd0d7", "3dd6823d3e04b5f223e3e265b4a1eae15f104f4366edd409e5a5e413a98f911f", "4064f53d4cce69e9ac613256dc2162e56f20a4e2d2086b1956dd2fcf77b7fac5", "4674f7d27a6c1c52a4d1aa5f0881f1eff840d2206989bae6acb1c7668c02ebfb", "7d42ab8cedd175b5ebcb39b5208b25ba104842489ed59fbb29356f671ac93583", "965df25449305092b23d5145b9bdaeb0149b6e41a77a7d728b1644b3c99277c1", "9c9d6531bc1886454f44aa8f809268bc481295cf9740827254f53c30104f074a", "a78e438db8ec26d5d9d0e584b27ef25c7afa5a182d1bf4d05e313d2d6d515271", "a7acefddf994af1aeba05bbbafe4ba983a187079f125146dc5859e6d817df824", "a87f59508c2b7ceb8631c20630118cc546f1f815e034193dc72390db038a5cb3", "ac792b385d81151bae2a5a8adb2b88261ceb4976dbfaaad9ce3a200e036753dc", "b03b2c0badeb606d1232e5f78852c102c0a7989d3a534b3129e7856a52f3d161", "b39321f1a74d1f9183bf1638a745b4fd6fe80efbb1f6b32b932a588b4bc7695f", "cae14a01a159b1ed91a324722d746523ec757357260c6804d11d6147a9e53e3f", "cd49930af1d1e49a812d987c2620ee63965b619257bd76eaaa95870ca08837cf", "e15b382603c58f24265c9c931c9a45eebf44fe2e6b4eaedbb0d025ab3255228b", "e91d31b34fc7c2c8f756b4e902f901f856ae53a93399368d9a0dc7be17ed2ca0", "ef627986941b5edd1ed74ba89ca43196ed197f1a206a3f18cc9faf2fb84fd675", "f718a7949d1c4f622ff548c572e0c03440b49b9531ff00e4ed5738b459f011e8"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fe53e0d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "fcc-mean-var-std" +version = "0.1.0" +description = "" +authors = ["Your Name "] + +[tool.poetry.dependencies] +python = "^3.8" +numpy = "^1.18" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" diff --git a/test_module.py b/test_module.py new file mode 100644 index 0000000..14f4dc8 --- /dev/null +++ b/test_module.py @@ -0,0 +1,21 @@ +import unittest +import mean_var_std + + +# the test case +class UnitTests(unittest.TestCase): + def test_calculate(self): + actual = mean_var_std.calculate([2,6,2,8,4,0,1,5,7]) + expected = {'mean': [[3.6666666666666665, 5.0, 3.0], [3.3333333333333335, 4.0, 4.333333333333333], 3.888888888888889], 'variance': [[9.555555555555557, 0.6666666666666666, 8.666666666666666], [3.555555555555556, 10.666666666666666, 6.222222222222221], 6.987654320987654], 'standard deviation': [[3.091206165165235, 0.816496580927726, 2.943920288775949], [1.8856180831641267, 3.265986323710904, 2.494438257849294], 2.6434171674156266], 'max': [[8, 6, 7], [6, 8, 7], 8], 'min': [[1, 4, 0], [2, 0, 1], 0], 'sum': [[11, 15, 9], [10, 12, 13], 35]} + self.assertAlmostEqual(actual, expected, "Expected different output when calling 'calculate()' with '[2,6,2,8,4,0,1,5,7]'") + + def test_calculate2(self): + actual = mean_var_std.calculate([9,1,5,3,3,3,2,9,0]) + expected = {'mean': [[4.666666666666667, 4.333333333333333, 2.6666666666666665], [5.0, 3.0, 3.6666666666666665], 3.888888888888889], 'variance': [[9.555555555555555, 11.555555555555557, 4.222222222222222], [10.666666666666666, 0.0, 14.888888888888891], 9.209876543209875], 'standard deviation': [[3.0912061651652345, 3.39934634239519, 2.0548046676563256], [3.265986323710904, 0.0, 3.8586123009300755], 3.0347778408328137], 'max': [[9, 9, 5], [9, 3, 9], 9], 'min': [[2, 1, 0], [1, 3, 0], 0], 'sum': [[14, 13, 8], [15, 9, 11], 35]} + self.assertAlmostEqual(actual, expected, "Expected different output when calling 'calculate()' with '[9,1,5,3,3,3,2,9,0]'") + + def test_calculate_with_few_digits(self): + self.assertRaisesRegex(ValueError, "List must contain nine numbers.", mean_var_std.calculate, [2,6,2,8,4,0,1,]) + +if __name__ == "__main__": + unittest.main()