giving up

This commit is contained in:
lda committed 2025-01-31 22:51:36 +07:00
1 parent d1a042206c
commit 4f8830ab5f
4 files changed
+299 -13

No files matched your search

+25 -10
View File
@@ -476,6 +476,10 @@ from collections import namedtuple
from numbers import Number from numbers import Number
from typing import Self from typing import Self
# a habit that you should take is that you should never blanket import.
# non of these import * in python, use ::* in rust, using namespace in c++, etc.
# only import what you need. the IDE will help you.
class BungeeJumper: class BungeeJumper:
""" """
@@ -517,8 +521,8 @@ class BungeeJumper:
@property @property
def t(self): def t(self):
"""current time """current time
we will not set time, change it through delta + special reset fn,
""" we will not set time, change it through delta + special reset fn,"""
return self.__time return self.__time
@property @property
@@ -590,6 +594,7 @@ class BungeeJumper:
"table": [i._asdict() for i in self.__table], "table": [i._asdict() for i in self.__table],
} }
# pylint flagged this for design choice, and i agree.
def bungee_import(self, t=None, dt=None, vt=None, m=None, cd=None, table=None): def bungee_import(self, t=None, dt=None, vt=None, m=None, cd=None, table=None):
"""overrides, also format from bungee_info only""" """overrides, also format from bungee_info only"""
if t is not None: if t is not None:
@@ -665,16 +670,16 @@ instance instead of doing nothing will be passed into methods as first argument.
yes, not javas `this`. `this` is a set name. yes, not javas `this`. `this` is a set name.
python `self` i could change it to whatever. instance will be passed to it. python `self` i could change it to whatever. instance will be passed to it.
That is a classmethod. That is a method.
a staticmethod has no such rules. a staticmethod has no such rules.
""" """
# do you know you can declare a class without even touching the word class at all? its the power of type(). # do you know you can declare a class without even touching the word class at all? its the power of type().
# however dont do this oh please
@classmethod def lda_set_example_arg(inst, arg):
def lda_set_example_arg(self, arg): inst.lda_example_instance_arg = arg
self.lda_example_instance_arg = arg
" __init__ is a magic function that will run when you make a class instance" " __init__ is a magic function that will run when you make a class instance"
@@ -694,13 +699,18 @@ LdaExampleClass = type(
LdaExampleClass.hello_to("lda") # prints hello lda! LdaExampleClass.hello_to("lda") # prints hello lda!
def lda_print_example_arg(self): def lda_print_example_arg(inst):
print("instance:", self.lda_example_instance_arg) print("instance:", inst.lda_example_instance_arg)
print("class:", self.lda_example_class_arg) print("class:", inst.lda_example_class_arg)
# @classmethod # class methods passes class as opposed of instance for first arg # i just knew this!
# def cls_print_example_arg(cls):
# print("class:", cls.lda_example_class_arg)
# print("instance:", cls.lda_example_instance_arg) # uh oh
# objects can freely add properties # objects can freely add properties
LdaExampleClass.lda_print_example_arg = classmethod(lda_print_example_arg) LdaExampleClass.lda_print_example_arg = lda_print_example_arg
# LdaExampleClass.cls_print_example_arg = cls_print_example_arg # see note below
lda1 = LdaExampleClass(3) # this must fit the args of self.__init__() lda1 = LdaExampleClass(3) # this must fit the args of self.__init__()
lda1.lda_print_example_arg() # pylint: disable=no-member # ide freak out lda1.lda_print_example_arg() # pylint: disable=no-member # ide freak out
@@ -708,6 +718,7 @@ lda1.lda_print_example_arg() # pylint: disable=no-member # ide freak out
# and class which is from the above which is 1. # and class which is from the above which is 1.
# Nothing was changed: i dont assign anything to anything in the functions # Nothing was changed: i dont assign anything to anything in the functions
# except for lda_set_example_arg # except for lda_set_example_arg
# lda1.cls_print_example_arg() # crashes as cls LdaExampleClass dont have lda_example_instance_arg instance variable
# dont do this, however, as ide will freak out. # dont do this, however, as ide will freak out.
@@ -723,6 +734,7 @@ copied_1_20 = one_to_20.copy() # this shallow copies
copied_1_20.append(21) copied_1_20.append(21)
assert copied_1_20 != one_to_20 assert copied_1_20 != one_to_20
assert copied_1_20[-2:] == [20, 21]
# if you have intellicode you can do ctrl + space to get that hints going. # if you have intellicode you can do ctrl + space to get that hints going.
@@ -731,3 +743,6 @@ ah yes intellicode.
You can view methods easily with intellisense if using vscode, You can view methods easily with intellisense if using vscode,
and you can also docs.python.org for more and you can also docs.python.org for more
""" """
# here is where you should be downloading jupyter to get the Tutorial2 Going.
# check its website. make sure you have the python, it is in PATH, and the pip exists. Or you can use poetry or miniconda. Or pipx. idfk do research.
+90 -3
View File
@@ -250,7 +250,7 @@
"try:\n", "try:\n",
" raise ValueError(\"value eroe\")\n", " raise ValueError(\"value eroe\")\n",
"except ValueError as error:\n", "except ValueError as error:\n",
" print(\"raised\", error)\n" " print(\"raised\", error)"
] ]
}, },
{ {
@@ -284,7 +284,8 @@
"\n", "\n",
" def quux(tis, arg1):\n", " def quux(tis, arg1):\n",
" return arg1, 42\n", " return arg1, 42\n",
" \n", "\n",
"\n",
"# usage:\n", "# usage:\n",
"\n", "\n",
"fbar = Foo()\n", "fbar = Foo()\n",
@@ -340,6 +341,92 @@
"source": [ "source": [
"do research broski\n", "do research broski\n",
"\n", "\n",
"## more python stuff\n",
"\n",
"### map and filter\n",
"\n",
"alot of time you would want to do stuff with the List and you would want to have a look at the builtin `map()` or `filter()` or those kind of functions:\n",
"\n",
"what they do is:\n",
"\n",
"```python\n",
"collection = [something, something_else,]\n",
"def function(x) -> y: ...\n",
"\n",
"new_collection = map(function, collection) \n",
"# => each x you run function on it and it returns y.\n",
"# put that y in the place x would be in the new_collection\n",
"\n",
"condition = lambda x: x == True\n",
"# lambda is a kind of mini throwaway function. you know closures? yes that\n",
"# but it can only do one thing. one singular expression fits in there. life is bad.\n",
"# tips. use def if this function deserves a name. for example ReLU is just\n",
"# ReLU = lambda x: x if x > 0 else 0\n",
"# but you would use want to do def ReLU(x: float) -> float as much as possible\n",
"\n",
"filtered_collection = filter(condition, collection)\n",
"# check for condition for each element of condition and append it into filtered_collection\n",
"```\n",
"\n",
"remember map and filter doesnt return a list back but a special generator object so you would have to call list() on it to use as list.\n",
"\n",
"why? for performance. generator is lazy."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"we also have this thing:\n",
"\n",
"### Python list comprehension\n",
"\n",
"comprehension. fuck do i know what it means. you dont know half these words and so do i.\n",
"\n",
"a simple way to do fiter_map ig"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# you would do this:\n",
"oldlist = list(range(1, 40, 3))\n",
"newlist = []\n",
"for i in oldlist: # notice this\n",
" if i % 5 == 0: # notice this\n",
" newlist.append(i)\n",
"\n",
"list_shorthand = [i for i in oldlist if i % 5 == 0]\n",
"\n",
"assert list_shorthand == newlist # same thing!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"its: \n",
"```python\n",
"something(vals) for vals in collection if condition(vals) if condition2(vals) if etc.\n",
"```\n",
"and `something(vals)` could well be another comprehension.\n",
"\n",
"notice for in if. strictly for in if, and not if for in. that if is of something else.\n",
"\n",
"oh but `something if condition else something_else` i also see how is that\n",
"\n",
"well that is another shorthand unrelated, but if you can use sure go ahead\n",
"\n",
"its kinda like the Ternary conditional operator `cond ? true_expr : false_expr` in c or typescript and yes you can go crazy with it just like with typescript"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## what the fuck is this half code half document\n", "## what the fuck is this half code half document\n",
"\n", "\n",
"jupyter. very flexible very dynamic. you can have jupyter running on browser or on vscode i think\n", "jupyter. very flexible very dynamic. you can have jupyter running on browser or on vscode i think\n",
@@ -368,7 +455,7 @@
"except ImportError:\n", "except ImportError:\n",
" print(\"python -m pip install numpy\")\n", " print(\"python -m pip install numpy\")\n",
"else:\n", "else:\n",
" print(np.array([[1, 5, 7], [2, 6, 8], [3, 4, 9]]))\n" " print(np.array([[1, 5, 7], [2, 6, 8], [3, 4, 9]]))"
] ]
}, },
{ {
+13
View File
@@ -0,0 +1,13 @@
# slide number 1
we will do it in jupyter notebook as it is better for this purpose
## what we kinda learn in slide 1
computer friendly calculation methods. its different to just math.
it is an approximation method for some of the harder problems that would be hard with math alone
it gets the job done for some people
doesnt for others
it idk
+171
View File
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# dont i hate this shit\n",
"\n",
"im manually translating the slides\n",
"\n",
"### why numpy and not pure python\n",
"\n",
"[../0/tutorial2.ipynb#numpy](../0/tutorial2.ipynb#numpy)\n",
"\n",
"### honestly\n",
"\n",
"[numpy beginners click here](https://numpy.org/doc/stable/user/absolute_beginners.html)\n",
"\n",
"## import steps. use for import\n",
"\n",
"you may need to:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "shellscript"
}
},
"outputs": [],
"source": [
"pip install numpy matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## usage\n",
"\n",
"make the list in python and then you np.array it and then feed the numpy array to numpy functions\n",
"\n",
"notice: make it\n",
"\n",
"1. with same size: `all(len(i) == len(j) for i in pyarray for j in pyarray) == True`\n",
"2. all elements have same type `all(type(i) == type(r[0]) for i in r for r in pyarray) == True`\n",
"\n",
"then you will be able to harness the peak of numpy. Or else goodbye"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pyarray = [\n",
" [1, 2, 3],\n",
" [4, 5, 6],\n",
"]\n",
"\n",
"\n",
"numpy_array = np.array(pyarray)\n",
"\n",
"pyarray, numpy_array"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"the 3:11:2 notation in python is called a slice object. numpy (probably) modified its `array.__index__` to yk accommodate to dimensions\n",
"\n",
"so normally you wouldnt fit more than one thing in that bracket: now you can! pretty great"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"newarr = numpy_array[:,1:3]\n",
"newarr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"kinda cool. normally it would be:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"[i[1:3] for i in pyarray[:]] #uh why so complicated"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"remember this: Python lists count from zero. Everything related to computer memory counts from 0. only Maniacs count from 1.\n",
"\n",
"also a tip for me actually, for i struggle with matrix rows and columns: `m2d[0,:]` is first Row. `m2d[:, 0]` is first Column. \n",
"row goes across. row number x is counted top down. Column goes top down. column number x is counted left to right "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### numpy array (matrix) operations\n",
"\n",
"the slides (and numpy also) have all the shit: the slice which we just covered, np.transpose `'`, np.matmul `*`, np.multiply `.*`, matrix divide `/` with np.dot and np.linarg.inv, np.divide `./`, concat arrays with np.concatenate np.stack or np.block etc.\n",
"\n",
"### math functions\n",
"\n",
"infinitely easier than matlab with python def\n",
"\n",
"you know exactly what this means:\n",
"\n",
"```python\n",
"def function(x):\n",
" return 3*x + 2\n",
"```\n",
"this WILL work with ndarrays as they do have `__mul__` `__rmul__` and `__add__`\n",
"\n",
"as opposed to matlab with its cumbersome ahh syms\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}