size

How to get size of array in bytes in perl?

对着背影说爱祢 提交于 2020-01-21 20:24:25
问题 I need get size of array in perl, but size must to be in bytes. I can not find any function for this. Thanks in advance 回答1: You can do this using the Devel::Size module -> https://metacpan.org/pod/Devel::Size #!/usr/bin/perl use strict; use warnings; use Devel::Size qw(total_size); my @arr = (1, 2, 3, "Foo", "Bar", "Baz", [4, 5, 6], {xyz => 2048}); print "Size: ", total_size(\@arr), " bytes.\n"; On my system this prints: bria@hel:~$ ./size.pl Size: 765 bytes. bria@hel:~$ 来源: https:/

pandas groupby and rank within groups that start with 1 for each group

不想你离开。 提交于 2020-01-21 12:47:24
问题 I have a dataframe: import pandas as pd df = pd.DataFrame([[1, 'a'], [1, 'a'], [1, 'b'], [1, 'a'], [2, 'a'], [2, 'b'], [2, 'a'], [2, 'b'], [3, 'b'], [3, 'a'], [3, 'b'], ], columns=['session', 'issue']) df I would like to rank issues within sessions. I tried with: df.groupby(['session', 'issue']).size().rank(ascending=False, method='dense') session issue 1 a 1.0 b 3.0 2 a 2.0 b 2.0 3 a 3.0 b 2.0 dtype: float64 What I need is result like this one: for group session=1, there are three a issues

lectcode-搜索二维矩阵

喜欢而已 提交于 2020-01-21 12:45:57
要求 编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性: 每行中的整数从左到右按升序排列。 每行的第一个整数大于前一行的最后一个整数。 示例 示例 1: 输入: matrix = [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ] target = 3 输出: true 示例 2: 输入: matrix = [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ] target = 13 输出: false 代码 顺序查找,先确定行,再确定列。 bool searchMatrix(vector<vector<int>>& matrix, int target) { int m = matrix.size(); int i = 0; if(m==0) return false; int n = matrix[0].size(); if(n==0) return false; for(;i<m;i++) { if(n==1&&matrix[i][0]==target) return true; if(n>1&&matrix[i][0]<=target&&target<=matrix[i][n-1]) break; } if(i==m) i = i-1

cfg.120

拈花ヽ惹草 提交于 2020-01-21 01:26:17
[net] #Testing #batch=64 #subdivisions=64 Training batch=64 subdivisions=32 width=960 height=960 channels=3 momentum=0.9 decay=0.0005 angle=0 saturation = 1.5 exposure = 1.5 hue=.1 learning_rate=0.0003 burn_in=1000 #1000 max_batches = 100000 #500200 policy=steps steps=80000,90000 #400000,450000 scales=.1,.1 [convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky Downsample [convolutional] batch_normalize=1 filters=64 size=3 stride=2 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=32 size=1 stride=1 pad=1 activation=leaky [convolutional] batch

leetcode 121 股票买卖问题系列

混江龙づ霸主 提交于 2020-01-20 06:58:31
描述: 给一些列数字,表示每条股票的价格,如果可以买卖一次(不能同一天买和卖),求最大利益(即差最大)。 其他三道问题是,如果能买卖无限次,买卖两次,买卖k次。 题一: 实质是求后面一个数减前一个数的最大差值。 维护一个最小值,和当前最大值。只需遍历一次,空间也是常数。 int maxProfit(vector<int>& prices) { if (prices.size() < 1) return 0; int min_ = prices[0]; int ret = 0; for (int i = 1; i < prices.size(); i++) { ret = max(ret, prices[i] - min_); min_ = min(min_, prices[i]); } return ret; } 题二: 只要是后一个数比前一个大,都增。 int maxProfit(vector<int>& prices) { if (prices.size() < 1) return 0; int ret = 0; for (int i = 0; i < prices.size() - 1; i++) { ret += max(prices[i + 1] - prices[i], 0); } return ret; } 题三: 可进行两次操作。 其中一个思路,可以关注分界点

scala mailbox size limit

不问归期 提交于 2020-01-20 03:52:05
问题 Can I set maximum size for an actor's mailbox in Scala? Take the Producer-Consumer problem. With threads I can block the producers when the buffer fills up. I saw a couple of producer-consumer examples written in Scala and they all use actors with mailboxes used as a "buffer". Can I set mailbox size to cause producers to wait until a consumer is ready? Any other elegant solution to avoid uncontrollable growth of mailboxes? 回答1: You can create an actor that acts as a buffer between the

将正方形矩阵顺时针旋转90度

北战南征 提交于 2020-01-19 00:36:09
题目 给定一个矩阵matrix,把矩阵顺时针转动90度: 1 2 3 4 5 6 7 8 9 -> 7 4 1 8 5 2 9 6 3 思路 比较简单的思路 1)先上下对称 -> 7 8 9 4 5 6 1 2 3 2)对角互换 -> 7 4 1 8 5 2 9 6 3 实现 def rotate ( matrix ) : if matrix is None or len ( matrix ) == 0 or len ( matrix [ 0 ] ) != len ( matrix ) : return size = len ( matrix ) for i in range ( size // 2 ) : matrix [ i ] , matrix [ size - i - 1 ] = matrix [ size - i - 1 ] , matrix [ i ] for i in range ( size ) : for j in range ( i ) : matrix [ i ] [ j ] , matrix [ j ] [ i ] = matrix [ j ] [ i ] , matrix [ i ] [ j ] return matrix 测试 def test_rotate ( size ) : n = 1 mat = [ ] for i in range ( size

How to change legend size with matplotlib.pyplot

五迷三道 提交于 2020-01-18 11:16:45
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc

How to change legend size with matplotlib.pyplot

百般思念 提交于 2020-01-18 11:13:24
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc

How to change legend size with matplotlib.pyplot

a 夏天 提交于 2020-01-18 11:12:11
问题 Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions') plot.scatter(k, data[:, 0], color='b', label='Dis 1: cf = .6, var = .2') plot.scatter(k, data[:, 1], color='r', label='Dis 2: cf = .2, var = .1') plot.scatter(k, data[:, 2], color='g', label='Dis 3: cf = .1, var = .01') plot.legend(loc