202104-25 pytorch tensor int型除法出现的问题 昨天晚上跑起来一个classification实验,今天发现训练loss在降,然而accuracy永远是0。。。直觉告诉我evaluation有问题然后发现自己写了个很愚蠢的bugaccuracy对应的tensor出来是int型的,我用到了一个除法取平均。而pytorch里无论用/or//结果都是取整,,accuracy一直就没有。。所以转换成float就没问题了,,低级bug,下不为例补充:pytorchtensordivision/除法除法的时候要注意数据类型的问题a=torch.div(torch.tensor... 继续阅读 >
202102-21 golang 中string和int类型相互转换 总结了golang中字符串和各种int类型之间的相互转换方式:string转成int:int,err:=strconv.Atoi(string)string转成int64:int64,err:=strconv.ParseInt(string,10,64)int转成string:string:=strconv.Itoa(int)int64转成string:string:=strconv.FormatInt(int64,10)字符串到float32/float64float32,err=ParseFloat(string,32)float64,err=ParseFloat(string,64)interface{}与其他类型之间的转换转换方式包括隐... 继续阅读 >
202101-13 python 进制转换 int、bin、oct、hex的原理 原理十进制转n进制都可以使用倒除法:对十进制进行除n的运算,直到商为0为止,然后将各个步骤中得到的余数倒着写出来.n进制转十进制:(例子:二进制转十进制)101001=>2^5+2^3+1=32+8+1=4110111=>2^4+2^2+2+1=16+4+2+1=23同样类推一下,n进制转十进制就是将2为底换成n为底就好了还有其他方法,比如使用中间二进制,例如,将十进制转成八进制或者十六进制,先转成二进制再转成八进制或者十六进制十... 继续阅读 >
202010-10 Java Integer及int装箱拆箱对比 示例代码:classBoxIntInteger{publicstaticvoidmain(String[]args){Integera=newInteger(10111);intb=10111;booleanequal1=a==b;booleanequal2=a.equals(b);System.out.println(equal1);System.out.println(equal2);}}反编译字节码:publicstaticvoidmain(Stringargs[]){Integera=newInteger(10111);intb=10111;booleanequal1=a.intValue()==b;boo... 继续阅读 >
202010-09 MySQL INT类型全解析 前言:整型是MySQL中最常用的字段类型之一,通常用于存储整数,其中int是整型中最常用的,对于int类型你是否真正了解呢?本文会带你熟悉int类型相关知识,也会介绍其他整型字段的使用。1.整型分类及存储范围整数类型字节有符号范围无符号范围TINYINT1-128~1270~255SMALLINT2-32768~327670~65535MEDIUMINT... 继续阅读 >
202009-27 解决Python 异常TypeError: cannot concatenate 'str' and 'int' objects TypeError:cannotconcatenate'str'and'int'objectsprintstr+int的时候就会这样了python+作为连接符的时候,不会自动给你把int转换成str补充知识:TypeError:cannotconcatenate'str'and'list'objects和Python读取和保存图片运行程序时报错,然后我将list转化为str就好了。利用''.join(list)如果需要用逗号隔开,如1,2,3,4则使用','.join(list)Python中plt可以显示和保存图片,不能使用mpingimportmatplotlib.ima... 继续阅读 >
202009-24 通过实例了解Java Integer类和int的区别 代码实例如下publicstaticvoidmain(String[]args){Integeri=10;Integerj=10;System.out.println(i==j);Integera=128;Integerb=128;System.out.println(a==b);intk=10;System.out.println(k==i);intkk=128;System.out.println(kk==a);Integerm=newInteger(10);Integern=newInteger(10);System.out.println(m==n);}我们使用反编译工具Jad,得到的... 继续阅读 >