Basic-python | some knowledge about basic python | Graph Database library
kandi X-RAY | Basic-python Summary
kandi X-RAY | Basic-python Summary
some knowledge about basic python
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Basic-python
Basic-python Key Features
Basic-python Examples and Code Snippets
Community Discussions
Trending Discussions on Basic-python
QUESTION
I'm playing around with Neural Nets and wanted to make a clean class implementation to handle any size net. Currently, I'm debugging my learning function to deal with 2-Layer networks.
In it's current state using logistic activation:
- It cannot learn values below 0.5
- It cannot handle matrices of input vectors (only single input vectors), this can be implemented later
- If initial weights and bias result in output less than 0.5, it will likely learn towards 0
- Assumption: In "ideal" conditions, it will learn any value between 0.5 and 1 using any combination of binary input
- This has been tested with 2 and 3 inputs to network
- Does proper forward propagation regardless of number of layers
Here's the relevant code:
...ANSWER
Answered 2021-Apr-06 at 07:46The one issue that immediately pops out is that your derivative of the sigmoid seems incorrect. The derivative of sigmoid(x) is not equal to (x)*(1-x) but sigmoid(x)(1-sigmoid(x))
You can change your implementation accordingly
QUESTION
Several places online, including answers in Stack Overflow (such as this, this & this), mention that Python iterators must implement both the __next__
method (which I understand) and the __iter__
method. These places rightfully conclude that all iterators are also iterables. Even PyCharm issues a type warning if a variable which is annotated to be a typing.Iterator
doesn't implement that __iter__
method.
Contrary to those, the official Python tutorial section on iterators only mentions the need for a __next__
method:
The function returns an iterator object that defines the method
__next__()
which accesses elements in the container one at a time
So my question is: do Python iterators formally need to be iterables on their own? I personally don't understand why this should be true, and why we can't fully separate the requirements for an Iterable
and an Iterator
.
ANSWER
Answered 2020-May-08 at 10:28That's the tutorial. It glosses over things. If you check the data model documentation, you'll see an explicit requirement that iterators support __iter__
:
The iterator objects themselves are required to support the following two methods, which together form the iterator protocol:
iterator.__iter__()
Return the iterator object itself. This is required to allow both containers and iterators to be used with the for and in statements. This method corresponds to the tp_iter slot of the type structure for Python objects in the Python/C API.
iterator.__next__()
...
Python easily could have been designed to make iterators non-iterable, the way Java did, but that would have been counterproductive. Iterating over iterators is extremely common and standard in Python, and it was always intended to be.
Having to stick some kind of iterwrapper
around iterators in every for
loop would be like having to stick some kind of addablewrapper
around your integers every time you wanted to add two integers.
QUESTION
I am trying to implement an iterable proxy for a web resource (lazily fetched images).
Firstly, I did (returning ids, in production those will be image buffers)
...ANSWER
Answered 2019-May-21 at 12:08Your __next__
method uses yield
, which makes it a generator function. Generator functions return a new iterator when called.
But the __next__
method is part of the iterator interface. It should not itself be an iterator. __next__
should return the next value, not something that returns all values(*).
Because you wanted to create an iterable, you can just make __iter__
the generator here:
QUESTION
I have been trying to code a neural network from scratch and have watched a couple of videos to see how it is implemented.
So I came across this guide that builds a simple neural network in Python.
...ANSWER
Answered 2019-Jul-13 at 02:00You are correct: you subtract the slope in gradient descent.
This is exactly what this program does, subtract the slope. l1.T.dot(l2_delta)
and X.T.dot(l1_delta)
are the negative slope, which is why the author of this code uses +=
as opposed to -=
.
QUESTION
I'm running a C++ application which tries to run python using the https://docs.python.org/3.5/extending/embedding.html function calls. This is the error that the application error message pipes are giving me.
class 'ImportError': Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try
git clean -xdf
(removes all files not under version control). Otherwise reinstall numpy.Original error was: /usr/local/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PyExc_UserWarning
I'm quite puzzled as this only occurs when embedding Python in C++ as the import works when I use it through the interpreter. I'm more interested in an answer that adds to my understanding than a quick do this or do that fix. I list some system/problem information below, and some other questions that I'm considering posting about the same topic. Any guidance is appreciated!
System/Problem information:
- Ubuntu 16.04, 64 bit
- Compiled Python 3.5.5 with enabled-shared
- numpy import works in the interpreter (python3.exe, and python3.5.exe)
- I have made sure that the PySys_SetPath() sets the same sys.path as the output from the interpreter:
import sys
,sys.path
- I can import other modules like PIL, and datetimeutil; however, numpy and pandas are not importable (pandas uses numpy or seems to)
- The embedded Python uses the following commands:
Py_Import_Import()
,Py_Initialize()
(I made sure. It is only called once.), etc., but it does not get a global lock on the interpreter. - The application is built with a CMake build system which compiles to MakeFiles for my system.
- Installed numpy-1.14.2 using pip 9.0.0 using the
pip3.5 install numpy
command - The python script that causes this error has one line:
import numpy
... - I do not have a .zip file that I'm importing files from.
- The .exe used by the Python embedded in the C++ is located at /usr/local/bin/python3 (used Py_GetProgramName() to determine this). This .exe is linked to the libpython3.5m.so.1.0, and the missing symbol lives in libpython3.5m.so.1.0 (ran nm)
ldd on multiarray.cpython-35m-x86_64-linux-gnu.so shows:
ldd multiarray.cpython-35m-x86_64-linux-gnu.so
linux-vdso.so.1 => (0x00007ffd9e36b000)
libopenblasp-r0-39a31c03.2.18.so => /usr/local/lib/python3.5/site-packages/numpy/core/./../.libs/libopenblasp-r0-39a31c03.2.18.so (0x00007fdbe149b000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fdbe1192000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fdbe0f75000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdbe0bab000) /lib64/ld-linux-x86-64.so.2 (0x00007fdbe3ed5000)
libgfortran-ed201abd.so.3.0.0 => /usr/local/lib/python3.5/site-packages/numpy/core/./../.libs/libgfortran-ed201abd.so.3.0.0 (0x00007fdbe08b1000)
I could/might try reinstalling numpy through different means, but I'm having trouble tracking why that might work.
At this point, I'm assuming some hole in my knowledge exists. I have looked at a lot of similar posts regarding not being able to import the multiarray component and numpy when embedding Python in C++; however, either none of them match my specific case or as I stated there exists a hole. Here are a list of sub-questions that I will probably be asking if no one sees anything in this setup that is obviously concerning. I'll probably update the questions with links when/if I ask them (After I polish them).
- How does the numpy multiarray.so link to the pythonX.X.so for symbol resolution? The ldd does not seem to suggest that it ever does. Asked this question at this link
- CMake Question non-related issue resolved in this question asked on 4/12/18 and answered on 4/16/18.
- Setting PYTHONPATH in .bashrc does not seem to update what Py_GetPath() returns, I had to add in the site-packages for imports through a different methodology to sys.path. It may only update the bash script environment variable which doesn't effect the C++.
I'm not asking for an answer for the above question list at this point, rather I'm giving more clues to where my gap in knowledge may be.
Thank you for taking time from your day to read this question. Any help is appreciated.
Edit: 4/17/18:Well, I found a work around, and I'm currently using it. Dunes question started making me think more closely about undefined symbols and how it could be a linker/compiler error or that the numpy import always expects an environment with those symbols already loaded into memory. This got me trying to install different versions of numpy to see if any of the older versions made a difference. They did not, but it did make the error thrown to be slightly different. When I googled that, this question appeared. The accepted answer gave me a work around by adding these two lines to the pythonInterface.cpp:
#include
dlopen("libpython3.5m.so.1.0", RTLD_LAZY | RTLD_GLOBAL)
These commands add the shared library to be loaded in and available to the cpython.multiarray.so.
This is not an ideal solution as pointing to a specific .so which may be different from machine to machine. It resolves the issue for now, but it also could lead to errors where mismatches of shared libraries can occur during the python call process if the linked library to the pythonInterface.so changes, and this line does not get updated. I believe a better answer can be achieved if this sub-question is answered, so I'm currently holding out on submitting or accepting an answer until then. Thanks!
...ANSWER
Answered 2019-May-07 at 08:56Root Cause
This error occurs because multiarray.cpython-35m-x86_64-linux-gnu.so
module in numpy depends on libpythonx.x.so
, be it is not explicit link the libpythonx.x.so
. So if you use ldd -d multiarray.cpython-35m-x86_64-linux-gnu.so
you will not see the python in the list.
Python doesn't have issue because python binary depends on libpython.x.x.so
, so when numpy load multiarray.cpython-35m-x86_64-linux-gnu.so
by using dlopen
. libdl.so
will try to resolve the undefined symbols by checking the dependent shared library of the main program which is python. It will find it in libpython.x.x.so
.
Solution
After knowing the root cause the solution is very easy, just help libdl.so
to be able to find libpython.x.x.so
. There are at least two way to achieve that:
- Use
dlopen("libpythonx.x.so", RTLD_GLOBAL)
. After open this so useRTLD_GLOBAL
flag, it make symbol in libpythonx.x.so available for symbol resolution of subsequently loaded shared objects. - In main program which embed python, add the
libpythonx.x.so
into its dependency library.
QUESTION
ANSWER
Answered 2019-Apr-18 at 22:23You've done nothing wrong - you've correctly demonstrated that a single layer ANN cannot perform non-linear separation!
XOR inputs are an example of data that is not linearly separable - simply put, if you plot them on an x-y grid, you can't draw a straight line to separate the "0" outputs from the "1" outputs. A single layer artificial neural network can only perform linear separation, so will fail to produce the correct output regardless of how you train it.
To solve the XOR problem you need to add an extra layer. It seems like you have two layers already (the input layer and the output layer), but it's actually a single layer network because there is only one layer of weights (syn0
). Add a second layer (following the example in the reference you provided) and see if the training results improve.
QUESTION
I am currently learning about how to code neural networks in numpy/python. I used the code from this tutorial and tried to adapt it to make an importable module. However, when i tried using my own dataset. It threw a numpy error ValueError: shapes (1,3) and (1,1) not aligned: 3 (dim 1) != 1 (dim 0)
.
I have already tried reshaping all of the matrices from (x,) to (x,1) but with no success. After a bit of reading around, transposing the arrays was also meant to fix the issue, but i tried that as well and no success there either.
Here is the module (called hidden_net):
...ANSWER
Answered 2019-Apr-14 at 08:17The lines below are wrong, layer0
is the input layer and does not contain any neurons.
QUESTION
I have a simple MYSQL pod sitting behind a MYSQL service.
Additionally I have another pod that is running a python process that is trying to connect to the MYSQL pod.
If I try connecting to the IP address of the MYSQL pod manually from the python pod, everything is A-OK. However if I try connecting to the MYSQL service then I get an error that I can't connect to MYSQL.
...ANSWER
Answered 2017-Jan-20 at 19:01So this was the exact correct behavior but I just misconfigured my pods.
For future people who are stuck:
The selector defined in a kubernetes service must match the label of the pod(s) you wish to serve. IE) In my MySqlService.yaml file I have the name selector for "mysqlpod":
QUESTION
I want to create a simple neural network and in my studies, I reached a concept called Gradient Descent
. That says:
Imagine that you had a red ball inside of a rounded bucket. Imagine further that the red ball is trying to find the bottom of the bucket. This is optimization.
I use this tutorial:
http://iamtrask.github.io/2015/07/27/python-network-part2/
But I can't understand when optimization happens. When gradient descent happens and most importantly, What is the relation with the rounded bucket example?
This website has another tutorial(basic method):
http://iamtrask.github.io/2015/07/12/basic-python-network/
According to this website, This one is not gradient descent but the second tutorial is the same is first one and it called gradient descent method. I can't understand these two differences.
...ANSWER
Answered 2018-May-14 at 15:26For classical neural networks you have two steps:
- Feeding inputs through the network
- Backpropagation of the error and correction of the weights (synapses) The second one is where gradient descent is used.
This is the example from your link http://iamtrask.github.io/2015/07/27/python-network-part2/
QUESTION
I realised I still don't quite understand how to implement an iterator class. So a class where one can "for-loop" over some of its contents.
I have looked at these answers (I still don't get it):
What exactly are Python's iterator, iterable, and iteration protocols?
As far as I understand, an iterable is one that implements __iter__
and returns an iterator which is something that has __next__
implemented.
From this I somehow understood that if I want my class to be an iterator, and iterable. I must define __iter__
to return self, and have __next__
defined. Am I wrong so far?
Here is a scaffold for my class:
...ANSWER
Answered 2018-Feb-07 at 17:47You can make the following changes:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Basic-python
You can use Basic-python like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page