numpy

Unable to solve the XOR problem with just two hidden neurons in Python

筅森魡賤 提交于 2021-02-06 11:27:36
问题 I have a small, 3 layer, neural network with two input neurons, two hidden neurons and one output neuron. I am trying to stick to the below format of using only 2 hidden neurons. I am trying to show how this can be used to behave as the XOR logic gate, however with just two hidden neurons I get the following poor output after 1,000,000 iterations! Input: 0 0 Output: [0.01039096] Input: 1 0 Output: [0.93708829] Input: 0 1 Output: [0.93599738] Input: 1 1 Output: [0.51917667] If I use three

Unable to solve the XOR problem with just two hidden neurons in Python

三世轮回 提交于 2021-02-06 11:27:01
问题 I have a small, 3 layer, neural network with two input neurons, two hidden neurons and one output neuron. I am trying to stick to the below format of using only 2 hidden neurons. I am trying to show how this can be used to behave as the XOR logic gate, however with just two hidden neurons I get the following poor output after 1,000,000 iterations! Input: 0 0 Output: [0.01039096] Input: 1 0 Output: [0.93708829] Input: 0 1 Output: [0.93599738] Input: 1 1 Output: [0.51917667] If I use three

Use numpy.argwhere to obtain the matching values in an np.array

拟墨画扇 提交于 2021-02-06 10:55:44
问题 I'd like to use np.argwhere() to obtain the values in an np.array . For example: z = np.arange(9).reshape(3,3) [[0 1 2] [3 4 5] [6 7 8]] zi = np.argwhere(z % 3 == 0) [[0 0] [1 0] [2 0]] I want this array: [0, 3, 6] and did this: t = [z[tuple(i)] for i in zi] # -> [0, 3, 6] I assume there is an easier way. 回答1: Why not simply use masking here: z [z % 3 == 0] For your sample matrix, this will generate: >>> z[z % 3 == 0] array([0, 3, 6]) If you pass a matrix with the same dimensions with

Use numpy.argwhere to obtain the matching values in an np.array

好久不见. 提交于 2021-02-06 10:55:28
问题 I'd like to use np.argwhere() to obtain the values in an np.array . For example: z = np.arange(9).reshape(3,3) [[0 1 2] [3 4 5] [6 7 8]] zi = np.argwhere(z % 3 == 0) [[0 0] [1 0] [2 0]] I want this array: [0, 3, 6] and did this: t = [z[tuple(i)] for i in zi] # -> [0, 3, 6] I assume there is an easier way. 回答1: Why not simply use masking here: z [z % 3 == 0] For your sample matrix, this will generate: >>> z[z % 3 == 0] array([0, 3, 6]) If you pass a matrix with the same dimensions with

Passing a numpy array to C++

早过忘川 提交于 2021-02-06 10:14:25
问题 I have some code writen in Python for which the output is a numpy array, and now I want to send that output to C++ code, where the heavy part of the calculations will be performed. I have tried using cython's public cdef , but I am running on some issues. I would appreciate your help! Here goes my code: pymodule.pyx : from pythonmodule import result # result is my numpy array import numpy as np cimport numpy as np cimport cython @cython.boundscheck(False) @cython.wraparound(False) cdef public

add a number to all odd or even indexed elements in numpy array without loops

与世无争的帅哥 提交于 2021-02-06 10:14:15
问题 Lets say your numpy array is: A = [1,1,2,3,4] You can simply do: A + .1 to add a number to that every element numpy array I am looking for a way to add a number to just the odd or even indexed numbers A[::2] +1 while keeping the entire array intact. Is it possible to add a number to all the odd or even indexed elements without any loops? 回答1: In [43]: A = np.array([1,1,2,3,4], dtype = 'float') In [44]: A[::2] += 0.1 In [45]: A Out[45]: array([ 1.1, 1. , 2.1, 3. , 4.1]) Note that this modifies

add a number to all odd or even indexed elements in numpy array without loops

匆匆过客 提交于 2021-02-06 10:13:47
问题 Lets say your numpy array is: A = [1,1,2,3,4] You can simply do: A + .1 to add a number to that every element numpy array I am looking for a way to add a number to just the odd or even indexed numbers A[::2] +1 while keeping the entire array intact. Is it possible to add a number to all the odd or even indexed elements without any loops? 回答1: In [43]: A = np.array([1,1,2,3,4], dtype = 'float') In [44]: A[::2] += 0.1 In [45]: A Out[45]: array([ 1.1, 1. , 2.1, 3. , 4.1]) Note that this modifies

How to convert numpy object array into str/unicode array?

不打扰是莪最后的温柔 提交于 2021-02-06 10:10:57
问题 Update: In lastest version of numpy (e.g., v1.8.1), this is no longer a issue. All the methods mentioned here now work as excepted. Original question: Using object dtype to store string array is convenient sometimes, especially when one needs to modify the content of a large array without prior knowledge about the maximum length of the strings, e.g., >>> import numpy as np >>> a = np.array([u'abc', u'12345'], dtype=object) At some point, one might want to convert the dtype back to unicode or

Finding polynomial roots using Python — Possible Numpy Extension Bug

隐身守侯 提交于 2021-02-06 09:05:01
问题 I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'. My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3 . (Simple) But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?) Could anyone please find the culprit in my code? Or is it simply a bug? from numpy.polynomial import Polynomial as P p = P([1, 5, 6]) p.roots() 回答1: Simply pass it in the other order, p = P([6, 5, 1]) 回答2: You could have realized this yourself if you had

Finding polynomial roots using Python — Possible Numpy Extension Bug

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-06 09:04:49
问题 I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'. My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3 . (Simple) But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?) Could anyone please find the culprit in my code? Or is it simply a bug? from numpy.polynomial import Polynomial as P p = P([1, 5, 6]) p.roots() 回答1: Simply pass it in the other order, p = P([6, 5, 1]) 回答2: You could have realized this yourself if you had