As an Amazon Associate I earn from qualifying purchases.
Python: Passing *args and **kwargs into a function
# *args is the usual notation for optional, non-keyword arguments
# **kwargs is the usual notation for optional, keyword arguments
def test_var_args(regular_argument, *args, **kwargs):
print ("- regular argument:", regular_argument)
for arg in args:
print ("- unnamed arguments arg:", arg)
for key in kwargs:
print ("- named arguments: %s: %s" % (key, kwargs[key]))
test_var_args(1, "two", 3, four=4, five="five")
- regular argument: 1 - unnamed arguments arg: two - unnamed arguments arg: 3 - named arguments: four: 4 - named arguments: five: five
find similar posts:
Python
0
comments
Python: Passing *args and **kwargs into a function
# *args is the usual notation for optional, non-keyword arguments
# **kwargs is the usual notation for optional, keyword arguments
def test_var_args(regular_argument, *args, **kwargs):
print ("- regular argument:", regular_argument)
for arg in args:
print ("- unnamed arguments arg:", arg)
for key in kwargs:
print ("- named arguments: %s: %s" % (key, kwargs[key]))
test_var_args(1, "two", 3, four=4, five="five")
- regular argument: 1
- unnamed arguments arg: two
- unnamed arguments arg: 3
- named arguments: four: 4
- named arguments: five: five
find similar posts:
Python
0
comments
Python bubble sort
Since I had to learn python for my machine learning and self-driving classes and I had to review the basics. Not to waste my efforts, I am creating a new guide, you can see more in:
https://github.com/UkiDLucas/python_zen_interviews
https://github.com/UkiDLucas/python_zen_interviews
def bubble_sort(the_list: list, verbose: int=0):
"""
author: @UkiDLcuas
This function changes the provided list.
The list can contain integers, decimal numbers, strings, etc.
The list is sorted in ascending order (first to last).
The function does not return anything.
"""
if verbose > 0:
iteration = 0
# count remining bubbles ( aka step backwards)
start = len(the_list)-1 # end, zero-based list
stop = 0 # beginning
step = -1 # backwards
for remaining_bubbles in range(start, stop, step):
for i in range(remaining_bubbles):
if verbose > 0:
iteration = iteration + 1
print("iteration", iteration, "remaining_bubbles", remaining_bubbles, "index", i)
print(" ", the_list)
print(" comparing if is", the_list[i], "bigger than", the_list[i+1])
if the_list[i] > the_list[i+1]:
# swap
temp = the_list[i+1] # temp placehoder for the value to be moved
the_list[i+1] = the_list[i] # bubble up
the_list[i] = temp # bubble down
if verbose > 0:
print("*** finished", len(the_list), "element list in ", iteration, "iterations")
find similar posts:
GitHub,
Python,
tech
0
comments
Python bubble sort
Since I had to learn python for my machine learning and self-driving classes and I had to review the basics. Not to waste my efforts, I am creating a new guide, you can see more in:
https://github.com/UkiDLucas/python_zen_interviews
https://github.com/UkiDLucas/python_zen_interviews
def bubble_sort(the_list: list, verbose: int=0):
"""
author: @UkiDLcuas
This function changes the provided list.
The list can contain integers, decimal numbers, strings, etc.
The list is sorted in ascending order (first to last).
The function does not return anything.
"""
if verbose > 0:
iteration = 0
# count remining bubbles ( aka step backwards)
start = len(the_list)-1 # end, zero-based list
stop = 0 # beginning
step = -1 # backwards
for remaining_bubbles in range(start, stop, step):
for i in range(remaining_bubbles):
if verbose > 0:
iteration = iteration + 1
print("iteration", iteration, "remaining_bubbles", remaining_bubbles, "index", i)
print(" ", the_list)
print(" comparing if is", the_list[i], "bigger than", the_list[i+1])
if the_list[i] > the_list[i+1]:
# swap
temp = the_list[i+1] # temp placehoder for the value to be moved
the_list[i+1] = the_list[i] # bubble up
the_list[i] = temp # bubble down
if verbose > 0:
print("*** finished", len(the_list), "element list in ", iteration, "iterations")
find similar posts:
GitHub,
Python
0
comments
Sailing on Amazon river? - No, not really.
This video is not related to sailing on great lakes, but it is amazing and worth seeing...
find similar posts:
sailing,
YouTube
0
comments
AWS
Notes on how I use Amazon AWS EC2 instances for Convolutional Deep Neural Networks Machine Learning, using powerful GPU CUDA configurations.
I have moved this post to:
https://ukidlucas.github.io/posts/AWS.html
I have moved this post to:
https://ukidlucas.github.io/posts/AWS.html
find similar posts:
Amazon,
AWS,
Keras,
Linux/Unix,
Python,
SSD
0
comments
AWS
Notes on how I use Amazon AWS EC2 instances for Convolutional Deep Neural Networks Machine Learning, using powerful GPU CUDA configurations.
I have moved this post to:
https://ukidlucas.github.io/posts/AWS.html
I have moved this post to:
https://ukidlucas.github.io/posts/AWS.html
find similar posts:
Amazon,
AWS,
Keras,
Linux/Unix,
Python,
SSD
0
comments
Ubuntu: installing TensorFlow for NVidia (CUDA) GPU
I am setting TensorFlow on:
- Ubuntu 16.04 LTS 64-bit
- 16 GiB RAM
- AMD Athlon(tm) II X4 640 Processor × 4
- GeForce GTX 1050 Ti/PCIe/SSE2
Check if you have NVidia CUDA GPU
uki@uki-p6710f:~$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c82 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 0fb9 (rev a1)
Check the name of your OS
uki@uki-p6710f:~$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
Check C compiler
uki@uki-p6710f:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Ubuntu Headers
uki@uki-p6710f:~$ sudo apt-get install linux-headers-$(uname -r)
[sudo] password for uki:
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-headers-4.4.0-62-generic is already the newest version (4.4.0-62.83).
linux-headers-4.4.0-62-generic set to manually installed.
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 89 not upgraded.
Download newest CUDA installer (1.4GB)
https://developer.nvidia.com/cuda-downloads
https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
Execute CUDA installer
cd ~/Downloads/
uki@uki-p6710f:~/Downloads$ ls -alt
Mar 5 14:54 cuda_8.0.61_375.26_linux.run
Mar 5 14:54 cuda_8.0.61_375.26_linux.run
Feb 2 09:53 NVIDIA-Linux-x86_64-375.10.run
Set environment variables
uki@uki-p6710f:~$ nano ~/.bashrcexport PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
uki@uki-p6710f:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-8.0/lib64
Install TensorFlow via pip3 (Python 3.5)
uki@uki-p6710f:~$ python --version
Python 3.5.2 :: Anaconda 4.3.0 (64-bit)
$ sudo apt install python3-pip
$ conda info --envs
# conda environments:
#
tensorflow /home/uki/anaconda3/envs/tensorflow
root * /home/uki/anaconda3
# conda environments:
#
tensorflow /home/uki/anaconda3/envs/tensorflow
root * /home/uki/anaconda3
$ conda env create -f /Users/ukilucas/dev/uki.guru/conda_enviroment_GPU.yml
$source activate tensorflow
Setting Jupyter kernel to match Python conda environment
http://ukitech.blogspot.com/2017/02/kernel.html
find similar posts:
CUDA,
GPU,
NVidia,
TensorFlow,
Ubuntu
0
comments
Ubuntu: installing TensorFlow for NVidia (CUDA) GPU
I am setting TensorFlow on:
- Ubuntu 16.04 LTS 64-bit
- 16 GiB RAM
- AMD Athlon(tm) II X4 640 Processor × 4
- GeForce GTX 1050 Ti/PCIe/SSE2
Check if you have NVidia CUDA GPU
uki@uki-p6710f:~$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c82 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 0fb9 (rev a1)
Check the name of your OS
uki@uki-p6710f:~$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
Check C compiler
uki@uki-p6710f:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Ubuntu Headers
uki@uki-p6710f:~$ sudo apt-get install linux-headers-$(uname -r)
[sudo] password for uki:
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-headers-4.4.0-62-generic is already the newest version (4.4.0-62.83).
linux-headers-4.4.0-62-generic set to manually installed.
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 89 not upgraded.
Download newest CUDA installer (1.4GB)
https://developer.nvidia.com/cuda-downloads
https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
Execute CUDA installer
cd ~/Downloads/uki@uki-p6710f:~/Downloads$ ls -alt
Mar 5 14:54 cuda_8.0.61_375.26_linux.run
Mar 5 14:54 cuda_8.0.61_375.26_linux.run
Feb 2 09:53 NVIDIA-Linux-x86_64-375.10.run
Set environment variables
uki@uki-p6710f:~$ nano ~/.bashrcexport PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
uki@uki-p6710f:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-8.0/lib64
Install TensorFlow via pip3 (Python 3.5)
uki@uki-p6710f:~$ python --version
Python 3.5.2 :: Anaconda 4.3.0 (64-bit)
$ sudo apt install python3-pip
$ conda info --envs
# conda environments:
#
tensorflow /home/uki/anaconda3/envs/tensorflow
root * /home/uki/anaconda3
# conda environments:
#
tensorflow /home/uki/anaconda3/envs/tensorflow
root * /home/uki/anaconda3
$ conda env create -f /Users/ukilucas/dev/uki.guru/conda_enviroment_GPU.yml
$source activate tensorflow
Setting Jupyter kernel to match Python conda environment
http://ukitech.blogspot.com/2017/02/kernel.html
find similar posts:
CUDA,
GPU,
NVidia,
TensorFlow,
Ubuntu
0
comments
Subscribe to:
Comments (Atom)
Post Scriptum
The views in this article are mine and do not reflect those of my employer.
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
LinkedIn
Google Scholar
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
Google Scholar
Popular Recent Posts
-
Keishin Kata (敬心形) of Shobudo (正武道) karate kei (敬) respect, reverence, or honor someone or something shin (心) heart or mind kata (形) fo...
-
Before arriving in Okinawa, several experiences prepared me for what I would eventually learn there. Karate was the first. It introduced me ...
-
I came across Ruri Ohama mentioning a book by Takafumi Horie and Yoichi Ochiai titled: “Job Atlas for 10 Years From Now. How Will You Live i...
-
Please look at the newer post: http://ukitech.blogspot.com/2009/09/eclipse-35-galileo-and-gwt-m2-svn.html 1) Upload a new version of Eclipse...
-
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space or Unable to execute dex: Java heap space Java h...
-
I have a habit of "stopping to smell the roses", or as in today's case, to take a photo of baby mushrooms on the forest floor....
-
http://code.google.com/apis/socialgraph/
-
Many online videos warn about vegetables you should never eat, especially those rich in oxalates. The tone is dramatic. The reality is much ...
Most Popular Articles
-
Affordance as a Function of Intent and Action? As a person passionate about Behavioral Sciences, I found myself unable to shake the impre...
-
Step 1: Register you app with Facebook. Sign in to Facebook using your standard credentials. Navigate to http://www.facebook.com/developer...
-
Please look at the newer post: http://ukitech.blogspot.com/2009/09/eclipse-35-galileo-and-gwt-m2-svn.html 1) Upload a new version of Eclipse...
-
Creating Android ROS nodes to: - add control UI (HMI) - utilize existing phone sensors: -- gyroscope -- GPS -- compass -- camera - do...
-
In this tutorial we will learn how to install the Intellij IDEA database plugin. Start with opening Settings > search for plugins ...
-
Installing TuriCreate on Python 3.6 Anaconda Environment 1) Check what Python version Apple Turi Create supports https://github.com/ap...
-
In this tutorial we will overview integration basics of Android Studio and Gradle build tools.
-
This tutorial shows you how to change the code lower/upper case of code in Android Studio.
-
ImportError : No module named 'sklearn.model_selection' Before doing the embarrassing things I did below, read this: Setting Jupy...
-
This minimal PyTorch example implements a custom recurrent neural network (RNN) cell from first principles, showing how sequence memory eme...
apt quotation..
“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.” by Robert A. Heinlein (author, aeronautical engineer, and naval officer)