num

画出8个高斯分布散点图

混江龙づ霸主 提交于 2020-03-09 10:14:00
import matplotlib.pyplot as plt import numpy as np num_mixtures = 8 radius = 2.0 std = 0.02 thetas = np.linspace(0, 2 * np.pi, num_mixtures + 1)[:num_mixtures] xs, ys = radius * np.sin(thetas), radius * np.cos(thetas) mix_coeffs=tuple([1 / num_mixtures] * num_mixtures) mean=tuple(zip(xs, ys)) cov=tuple([(std, std)] * num_mixtures) ax = None epoch = 0 fig = None def gmm_sample(num_samples, mix_coeffs, mean, cov): z = np.random.multinomial(num_samples, mix_coeffs) samples = np.zeros(shape=[num_samples, len(mean[0])]) i_start = 0 for i in range(len(mix_coeffs)): i_end = i_start + z[i] samples[i

hdu 2071 Max Num

我的梦境 提交于 2020-03-09 09:46:47
Problem Description There are some students in a class, Can you help teacher find the highest student . Input There are some cases. The first line contains an integer t, indicate the cases; Each case have an integer n ( 1 ≤ n ≤ 100 ) , followed n students’ height. Output For each case output the highest height, the height to two decimal plases; Sample Input 2 3 170.00 165.00 180.00 4 165.00 182.00 172.00 160.00 Sample Output 180.00 182.00 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <queue> #include <deque> #include

很值得套用的keras经典Unet版本

无人久伴 提交于 2020-03-09 09:37:13
代码如下: 1 from model import * 2 from data import *#导入这两个文件中的所有函数 3 4 #os.environ[“CUDA_VISIBLE_DEVICES”] = “0” 5 6 7 data_gen_args = dict(rotation_range=0.2, 8 width_shift_range=0.05, 9 height_shift_range=0.05, 10 shear_range=0.05, 11 zoom_range=0.05, 12 horizontal_flip=True, 13 fill_mode=‘nearest’)#数据增强时的变换方式的字典 14 myGene = trainGenerator(2,‘data/membrane/train’,‘image’,‘label’,data_gen_args,save_to_dir = None) 15 #得到一个生成器,以batch=2的速率无限生成增强后的数据 16 17 model = unet() 18 model_checkpoint = ModelCheckpoint(‘unet_membrane.hdf5’, monitor=‘loss’,verbose=1, save_best_only=True) 19 #回调函数,第一个是保存模型路径

java8新特性

匆匆过客 提交于 2020-03-09 09:24:55
Home Introduction Java 8 简明教程 Java 8 数据流教程 Java 8 Nashorn 教程 Java 8 并发教程:线程和执行器 Java 8 并发教程:同步和锁 Java 8 并发教程:原子变量和 ConcurrentMap Java 8 API 示例:字符串、数值、算术和文件 在 Java 8 中避免 Null 检查 使用 Intellij IDEA 解决 Java 8 的数据流问题 在 Nashron 中使用 Backbone.js Published with GitBook Java 8 简明教程 Java 8 简明教程 原文: Java 8 Tutorial 译者: ImportNew.com - 黄小非 来源: Java 8简明教程 ‍ “Java并没有没落,人们很快就会发现这一点” 欢迎阅读我编写的 Java 8 介绍。本教程将带领你一步一步地认识这门语言的新特性。通过简单明了的代码示例,你将会学习到如何使用默认接口方法,Lambda表达式,方法引用和重复注解。看完这篇教程后,你还将对最新推出的 API 有一定的了解,例如:流控制,函数式接口,map扩展和新的时间日期API等等。 允许在接口中有默认方法实现 Java 8 允许我们使用default关键字,为接口声明添加非抽象的方法实现。这个特性又被称为 扩展方法

完全平方数

为君一笑 提交于 2020-03-09 08:55:27
给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n。你需要让组成和的完全平方数的个数最少。 示例 1: 输入: n = 12 输出: 3 解释: 12 = 4 + 4 + 4. 示例 2: 输入: n = 13 输出: 2 解释: 13 = 4 + 9. 方法1:深度优先(BFS) 1 public class T279 { 2 public int numSquares(int n) { 3 List<Integer> squareList = getSquareArray(n); 4 Queue<Integer> que = new LinkedList<>(); 5 que.add(n); 6 boolean[] visited = new boolean[n]; 7 int level = 0; 8 while (!que.isEmpty()) { 9 int size = que.size(); 10 level++; 11 while (size-- > 0) { 12 int num = que.poll(); 13 for (int square : squareList) { 14 int left = num - square; 15 if (left == 0) { 16 return level; 17 }

第四讲作业

我的未来我决定 提交于 2020-03-09 08:14:41
1、简述普通参数、指定参数、默认参数、动态参数的区别 普通参数:以正确的顺序传入函数,调用时数量必须和声明的一样。 指定参数:参数和函数调用关系密切,函数调用使用使用关键字参数来确定传入的参数值,参数允许函数调用时参数的顺序和声明时不一致。 默认参数:函数进行调用时,如果没有新的参数传入则默认的情况下,就调用默认参数 动态参数:个函数能处理比当初声明时更多的参数,这些参数叫动态参数 2、写函数,计算传入的字符串中数字、字母、空格、以及其他的个数 #####判断字母数字出现的次数######## def func1(s):#定义一个函数 #字符串中出现的数字、字母、空格等其他的符号,初始值为0 zimu_num = 0 kongge_num = 0 shuzi_num = 0 qita_num = 0 for i in s:#对字符串进行循环判断 if i.isalpha(): zimu_num += 1 elif i.isspace(): kongge_num += 1 elif i.isdigit(): shuzi_num += 1 else: qita_num += 1 return (zimu_num,kongge_num,shuzi_num,qita_num)#把所有的结果返回到一个元组中 m = func1("wewqe-*- **-wqeqe")#调用func1函数

Leecode palindrome-number

淺唱寂寞╮ 提交于 2020-03-09 08:00:57
题目描述 在不使用额外的内存空间的条件下判断一个整数是否是回文 提示: 负整数可以是回文吗?(比如-1) 如果你在考虑将数字转化为字符串的话,请注意一下不能使用额外空间的限制 你可以将整数翻转。但是,如果你做过题目“Reverse Integer”,你会知道将整数翻转可能会出现溢出的情况,你怎么处理这个问题? 这道题有更具普遍性的解法。 分析 负数不是回文 对于可能是回文的数字这样判断: 设置一个div变量,和要判断的数保持位数相同,最高位为1,其他位为0,如 判断num=8428时,div := 1000。 这时判断 8428/div = 8(最高位) 和 8421%10 = 8(最低位) 是否相等,如果不相等,直接返回false。否则,将数字 num = 8428 变成 42,div变成10,继续判断… java 代码 public class Solution { public boolean isPalindrome ( int x ) { if ( x < 0 ) { return false ; } int div = 1 ; while ( x / div >= 10 ) { div = div * 10 ; } int num = x ; int left = 0 ; int right = 0 ; while ( div != 0 ) { left = num /

java基础语法

。_饼干妹妹 提交于 2020-03-09 07:43:58
一 规则 1 命名规则 A:类名称首字母大写,尽可能采取驼峰式命名:MaLin HelloWorld B:命名标识符规范:数字、字母、下划线、$组成,但是不能以数字开头,不能是关键字或者保留字。例如:3max 3d goto C:变量名称 :首字母必须小写 常量:必须全大些 PI MAX D: 方法名称:首字母必须小写 2 严格区分大小写 3 以分号 ‘;’ 结束 二 数据类型 A:基本数据类型(四类八种) 1. 简单类型 2. 封装类型 (数据类型转换简单类型) Byte Short Integer Long Float Double Character Boolean 1.基本类型只能按值传递,而每个基本类型对应的封装类是按引用传递的。 2.从性能上说java中的基本类型是在堆栈上创建的,而所有的对象类型都是在堆上创建的,(对象的引用在堆栈上创建) B: 引用类型 1.数组 2.类(对象) 3.接口 说明: 机器语言(二进制语言):由 1 、 0 构成。 例如: 00000101 最小单位:bit 位 8bit = 1byte(字节、字符) ‘a’~’z’ ‘A’~’Z’ ‘0’~’9’ 特殊符号 一个中文汉字=2个字节=16位 ‘好’ 1024byte = 1KB 1024kb = 1mb 1024mb = 1gb 1024gb = 1tb 包:本质文件夹目录 java

LeetCode 179周赛题解

北城余情 提交于 2020-03-09 06:49:39
5352. 生成每种字符都是奇数个的字符串 1 class Solution { 2 public: 3 string generateTheString(int n) { 4 string ans=""; 5 if(n%2==1){ 6 for(int i=0;i<n;i++){ 7 ans+='a'; 8 } 9 }else{ 10 for(int i=0;i<n-1;i++){ 11 ans+='a'; 12 } 13 ans+='b'; 14 } 15 return ans; 16 } 17 }; 5353. 灯泡开关 III 解法一:找规律:当最大亮灯的位置与亮灯的数量相同的时候,那么亮起蓝灯: 1 class Solution { 2 public: 3 ///当开灯数与最大亮灯的位置相等的时候,那么灯就变成蓝色了 4 int numTimesAllBlue(vector<int>& light) { 5 int n=light.size(); 6 int max_num=0;//记录最大的亮的灯位置 7 int cnt=0;//记录亮灯的数量 8 int ans=0; 9 for(int i=0;i<n;i++){ 10 max_num=max(max_num,light[i]); 11 cnt++; 12 if(cnt==max_num){ 13 ans++; 14

十进制(0~2147483647)转任意进制(2进制~16进制)。

ぃ、小莉子 提交于 2020-03-09 04:46:57
# include <stdio.h> void main ( ) { int num , radix , i = 0 ; char res [ 32 ] = { '0' } , table [ ] = "0123456789ABCDEF" ; printf ( "Please enter the value to be converted:" ) ; scanf ( "%d" , & num ) ; printf ( "Please enter the radix to be converted:" ) ; scanf ( "%d" , & radix ) ; if ( num == 0 ) i = 1 ; while ( num > 0 ) { res [ i ++ ] = table [ num % radix ] ; num = num / radix ; } printf ( "Result:" ) ; while ( -- i >= 0 ) printf ( "%c" , res [ i ] ) ; } 来源: CSDN 作者: 轻松的小希 链接: https://blog.csdn.net/qq_38490457/article/details/104739322