subtraction

Python numpy subtraction no negative numbers (4-6 gives 254)

戏子无情 提交于 2019-12-04 02:10:22
I wish to subtract 2 gray human faces from each other to see the difference, but I encounter a problem that subtracting e.g. [4] - [6] gives [254] instead of [-2] (or difference: [2]). print(type(face)) #<type 'numpy.ndarray'> print(face.shape) #(270, 270) print(type(nface)) #<type 'numpy.ndarray'> print(nface.shape) #(270, 270) #This is what I want to do: sface = face - self.nface #or sface = np.subtract(face, self.nface) Both don't give negative numbers but instead subtract the rest after 0 from 255. Output example of sface: [[ 8 255 8 ..., 0 252 3] [ 24 18 14 ..., 255 254 254] [ 12 12 12 ..

What is a subtraction function that is similar to sum() for subtracting items in list?

痞子三分冷 提交于 2019-12-04 00:38:09
问题 I am trying to create a calculator, but I am having trouble writing a function that will subtract numbers from a list. For example: class Calculator(object): def __init__(self, args): self.args = args def subtract_numbers(self, *args): return ***here is where I need the subtraction function to be**** For addition, I can simply use return sum(args) to calculate the total but I am unsure of what I can do for subtractions. 回答1: from functools import reduce # omit on Python 2 import operator a =

R programming: How can I compute the difference between two cells in a data frame and save them in a new column

梦想与她 提交于 2019-12-03 16:10:12
Trying to learn R and am stuck on an autocorrelation example. I want to regress the difference in x against the difference in y. I have x and y in a data frame, and would like the difference of x2 - x1 to be saved in a new column say dx. I have no idea how to go about this. what I have: data1 x y 5 3 8 9 3 1 1 5 . . . . . . what I would like to get: data1.dif x y dx dy 5 3 NA NA 8 9 3 6 3 1 -5 -8 1 5 -2 4 . . . . . . . . Use diff , and stick an NA to the beginning of the resulting vectors. e.g. data1 <- read.table(text=' x y 1 5 3 2 8 9 3 3 1 4 1 5') # diff calculates the difference between

Trim/subtract CGPath from CGPath?

≡放荡痞女 提交于 2019-12-03 03:00:04
I have some CGPath (a poly with two circle) carried out on a CAShapeLayer . Can I trim/subtract paths like this? Instead of do the math, the result can be achieved at drawing time using kCGBlendModeClear . // Create the poly. CGContextBeginPath(context); CGContextMoveToPoint (context, a_.x, a_.y); CGContextAddLineToPoint (context, b_.x, b_.y); CGContextAddLineToPoint (context, c_.x, c_.y); CGContextAddLineToPoint (context, d_.x, d_.y); CGContextClosePath(context); // Draw with the desired color. CGContextSetFillColorWithColor(context, self.color.CGColor); CGContextFillPath(context); // Create

jQuery: detecting a browser resize

☆樱花仙子☆ 提交于 2019-12-02 23:18:29
I am using this script from snipplr, How would I set it so the container div is 100px less than the newWindowHeight height, like -100 or something. <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ //If the User resizes the window, adjust the #container height $(window).bind("resize", resizeWindow); function resizeWindow( e ) { var newWindowHeight = $(window).height(); $("#container").css("max-height", newWindowHeight ); } }); </script> The script you found over-complicated the issue. The following worked for me: $(function(){ // Cache reference to our container var

面向对象编写一个计算器

匿名 (未验证) 提交于 2019-12-02 22:56:40
首先分析计算器有加减乘除,取模,求余等计算方式,所以我们在创建了这个类的同时就应该想到后期肯定需要进行这方面的扩展,所以在设计的时候就应该尽量不修改原有代码的前提下进行功能的扩展,也就是降低对象之间的耦合度。 废话不多说,代码如下: namespace Program { //显示抽象类 public abstract class Print { public decimal Result { get; set; } public Print(decimal result) { this.Result = result; } public abstract void print(); } public class shuchu1 : Print { public shuchu1(decimal result) : base(result) { } public override void print() { Console.WriteLine("输出方式1输出" + Result); } } public class shuchu2 : Print { public shuchu2(decimal result) : base(result) { } public override void print() { Console.WriteLine("输出方式2输出" +

How to remove a pandas dataframe from another dataframe

不打扰是莪最后的温柔 提交于 2019-12-02 18:08:37
How to remove a pandas dataframe from another dataframe, just like the set subtraction: a=[1,2,3,4,5] b=[1,5] a-b=[2,3,4] And now we have two pandas dataframe, how to remove df2 from df1: In [5]: df1=pd.DataFrame([[1,2],[3,4],[5,6]],columns=['a','b']) In [6]: df1 Out[6]: a b 0 1 2 1 3 4 2 5 6 In [9]: df2=pd.DataFrame([[1,2],[5,6]],columns=['a','b']) In [10]: df2 Out[10]: a b 0 1 2 1 5 6 Then we expect df1-df2 result will be: In [14]: df Out[14]: a b 0 3 4 How to do it? Thank you. Solution Use pd.concat followed by drop_duplicates(keep=False) pd.concat([df1, df2, df2]).drop_duplicates(keep

I want to simply subtract elements from two lists

♀尐吖头ヾ 提交于 2019-12-02 14:36:00
问题 I have two open lists. First Weight ( fWeight ) and Second Weight ( sWeight ). I want to subtract the fWeight from sWeight . I am getting this error: unsupported operand type(s) for -: 'list' and 'list'. Is there a a simple solution for this? names_array = list() firstWeight_Array=list() students = 2 for i in range(students): name = str(raw_input("Please enter a name:")) names_array.append(str(name)) fWeight = int(raw_input("Please enter the first weight:")) firstWeight_Array.append(int

Subtracting two pointers giving unexpected result

岁酱吖の 提交于 2019-12-02 08:41:32
#include <stdio.h> int main() { int *p = 100; int *q = 92; printf("%d\n", p - q); //prints 2 } Shouldn't the output of above program be 8? Instead I get 2. Undefined behavior aside, this is the behavior that you get with pointer arithmetic: when it is legal to subtract pointers, their difference represents the number of data items between the pointers. In case of int which on your system uses four bytes per int , the difference between pointers that are eight-bytes apart is (8 / 4) , which works out to 2 . Here is a version that has no undefined behavior: int data[10]; int *p = &data[2]; int

Prolog search for possible combination for subtracting 2 elements from a list

巧了我就是萌 提交于 2019-12-02 04:15:34
This is an extended problem from this page. Prolog possible removal of elements in a list For example, for a list X = [1,2,3], I can subtract like following: subtract 1 from 1st / 2nd element, and X becomes [1-1, 2-1, 3] = [0, 1, 3] = [1, 3] subtract 1 from 1st / 3rd element: X becomes [2, 2] subtract 1 from 2nd / 3rd element: X becomes [1, 1, 2] subtract 2 from 2nd / 3rd element: X becomes[1, 1] So, it is always subtracting 2 elements, and with the same number, but always a real number. Have anyone got any ideas on this? This looks better: subt_comb(X, Y). X = [1,2,3] Y = [1,3] Y = [2,2] Y =