math

Decomposing a value into results of powers of two

纵然是瞬间 提交于 2020-05-09 15:49:31
问题 Is it possible to get the integers that, being results of powers of two, forms a value? Example: 129 resolves [1, 128] 77 resolves [1, 4, 8, 64] I already thought about using Math.log and doing also a foreach with a bitwise comparator. Is any other more beautiful solution? 回答1: The easiest way is to use a single bit value, starting with 1 and shift that bit 'left' until its value is greater than the value to check, comparing each bit step bitwise with the value. The bits that are set can be

How to fill space to border with in Matplotlib [duplicate]

眉间皱痕 提交于 2020-05-09 08:08:21
问题 This question already has answers here : Matplotlib fill between multiple lines (3 answers) Closed last month . I need to fill space between 3 graphs but I don't understand how to limit the area on the graph y2 import numpy as np import matplotlib.pyplot as plt y = lambda z: (4 * z - z ** 2) ** (1 / 2) y1 = lambda x: (8 * x - x ** 2) ** (1 / 2) y2 = lambda c: c * 3 ** (1 / 2) x = np.linspace(0, 12, 100) z = np.linspace(0, 12, 100) c = np.linspace(0, 12, 100) plt.ylim(0, 4) plt.xlim(0, 4) plt

How to fill space to border with in Matplotlib [duplicate]

那年仲夏 提交于 2020-05-09 08:08:08
问题 This question already has answers here : Matplotlib fill between multiple lines (3 answers) Closed last month . I need to fill space between 3 graphs but I don't understand how to limit the area on the graph y2 import numpy as np import matplotlib.pyplot as plt y = lambda z: (4 * z - z ** 2) ** (1 / 2) y1 = lambda x: (8 * x - x ** 2) ** (1 / 2) y2 = lambda c: c * 3 ** (1 / 2) x = np.linspace(0, 12, 100) z = np.linspace(0, 12, 100) c = np.linspace(0, 12, 100) plt.ylim(0, 4) plt.xlim(0, 4) plt

Rounding to 100% for pie chart

霸气de小男生 提交于 2020-04-19 19:07:17
问题 I am taking the sum 3 random existing whole numbers and then dividing each individual number by the sum to get the percentage. What is the best way to guarantee I will always get 100%? Is there any vb.net function that will help me with this or do I basically have to manually find the difference between the sum of my 3 percentages and 100%, divide it, and add it to my 3 percentages. 回答1: You calculate the percentages, add all but the last together and subtract from 100. If you ry to

Rounding to 100% for pie chart

爱⌒轻易说出口 提交于 2020-04-19 18:59:55
问题 I am taking the sum 3 random existing whole numbers and then dividing each individual number by the sum to get the percentage. What is the best way to guarantee I will always get 100%? Is there any vb.net function that will help me with this or do I basically have to manually find the difference between the sum of my 3 percentages and 100%, divide it, and add it to my 3 percentages. 回答1: You calculate the percentages, add all but the last together and subtract from 100. If you ry to

Rounding to 100% for pie chart

笑着哭i 提交于 2020-04-19 18:58:15
问题 I am taking the sum 3 random existing whole numbers and then dividing each individual number by the sum to get the percentage. What is the best way to guarantee I will always get 100%? Is there any vb.net function that will help me with this or do I basically have to manually find the difference between the sum of my 3 percentages and 100%, divide it, and add it to my 3 percentages. 回答1: You calculate the percentages, add all but the last together and subtract from 100. If you ry to

Rounding to 100% for pie chart

家住魔仙堡 提交于 2020-04-19 18:56:26
问题 I am taking the sum 3 random existing whole numbers and then dividing each individual number by the sum to get the percentage. What is the best way to guarantee I will always get 100%? Is there any vb.net function that will help me with this or do I basically have to manually find the difference between the sum of my 3 percentages and 100%, divide it, and add it to my 3 percentages. 回答1: You calculate the percentages, add all but the last together and subtract from 100. If you ry to

Simple neural network gives wrong output after training

前提是你 提交于 2020-04-18 06:10:17
问题 I've been working on a simple neural network. It takes in a data set with 3 columns, if the first column's value is a 1, then the output should be a 1. I've provided comments so it is easier to follow. Code is as follows: import numpy as np import random def sigmoid_derivative(x): return x * (1 - x) def sigmoid(x): return 1 / (1 + np.exp(-x)) def think(weights, inputs): sum = (weights[0] * inputs[0]) + (weights[1] * inputs[1]) + (weights[2] * inputs[2]) return sigmoid(sum) if __name__ == "_

How do you check if a mouse press is on a line in Java

点点圈 提交于 2020-04-18 05:43:20
问题 I am creating a java application and wanting to make it so that a user can click on a line in order to make an event occur. The line is simply defined by its 2 endpoints, both of which have a x and a y coordinate. Any ideas on how I can I can check if a position collected from the mouse press event (with a x and y coordinate) can be checked to see if it is on this line? I want to make it so that the hit detection for the line is a little bit forgiving for the user so that as long as the mouse

Why is set function on a numpy array returning slightly different values?

ⅰ亾dé卋堺 提交于 2020-04-18 05:42:34
问题 I had to check whether a matrix had eigenvalue with multiplicity>1 or not. Using numpy's eig function I got an array and converted it into set,which should remove the repeated eigenvalue and comparing the length of the list and the set,we can infer whether whether there are repeated eigenvalues or not.The code is given below- from numpy.linalg import eig A=[[3,1,1],[2,4,2],[-1,-1,1]] if len(eig(A)[0])!=len(set(eig(A)[0])): print "Multiple eigenvalues found!" else: print "All distinct" I got