array

[matplotlib]2.条形图

末鹿安然 提交于 2020-02-25 14:53:25
条形图 plt.bar() matplotlib . pyplot . bar ( x , height , width = 0.8 , bottom = None , * , align = 'center' , data = None , ** kwargs ) [ source ] 1.参数 参数 含义 类型 x x轴含义 sequence of scalars height 对应的条形的高度 scalar or sequence of scalars width 条形的宽 scalar or array-like, optional,默认0.8 2.例子 2.1 例1 普通条形图 import matplotlib . pyplot as plt import numpy as np x = [ 1 , 2 , 3 , 4 , 5 ] y = [ 10 , 20 , 30 , 40 , 50 ] plt . bar ( x , height = y ) plt . show ( ) 2.2 例2 x轴为字符串 import matplotlib . pyplot as plt import numpy as np x = [ 'a' , 'b' , 'c' , 'd' , 'e' ] y = [ 10 , 20 , 30 , 40 , 50 ] plt . bar ( x

Codeforces Round #624 (Div. 3)B. WeirdSort

余生颓废 提交于 2020-02-25 14:51:45
You are also given a set of distinct positions p1,p2,…,pm, where 1≤pi<n. The position pi means that you can swap elements a[pi] and a[pi+1]. You can apply this operation any number of times for each of the given positions. Your task is to determine if it is possible to sort the initial array in non-decreasing order (a1≤a2≤⋯≤an) using only allowed swaps. For example, if a=[3,2,1] and p=[1,2], then we can first swap elements a[2] and a[3] (because position 2 is contained in the given set p). We get the array a=[3,1,2]. Then we swap a[1] and a[2] (position 1 is also contained in p). We get the

查询Array中确定数值的对象&JS linq使用 = linq.js

时光毁灭记忆、已成空白 提交于 2020-02-24 16:48:13
var x=new Array(); x.push({"a":3,"b":3},{"a":2,"b":2},{"a":2,"b":4}); $.map(a,function(n){if(n.a==2){return a.indexOf(n)}})//结果Array [ 1,2 ] //本来想直接在里面删除的,但是这样是不可以的 $.map(x,function(n){if(n.a==2){x.splice(x.indexOf(n));return false;}})//TypeError: n is undefined ,这是因为map查到一个之后,会继续下一步, //但是因为x进行了移除操作,导致原有顺序出错,对象获取异常,和后台的写法是一个意思,不过如果查到的本身就是最后一个,则会正常执行的。 //和for循环一样,如果删除了一个之后,length就会不一样,导致数组最后一个对象获取出错 http://linqjs.codeplex.com/ https://jslinq.codeplex.com/downloads/get/71965 jslinq的下载地址,第一个应该是的,第二个地址没怎么看。 linq.js是用来让js中的对象能够像后端一样的查询等操作,反正感觉挺厉害的(自己太渣了) 今天需要去除json数据中某个确定字段值的Object,因为找不到能够直接查的方法

算法(二维数组的查找)

不羁岁月 提交于 2020-02-24 14:26:20
在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 要设计到二维数组中元素的查找,可以从左下或者右上开始查找,具体代码如下: public class Solution { public boolean Find ( int target , int [ ] [ ] array ) { if ( array == null || array . length == 0 || array [ 0 ] . length == 0 ) return false ; boolean flag = false ; for ( int j = 0 ; j < array [ 0 ] . length ; j ++ ) { if ( array [ array . length - 1 ] [ j ] >= target ) { for ( int i = 0 ; i < array . length ; i ++ ) { if ( array [ i ] [ j ] == target ) { flag = true ; } } } } return flag ; } } 来源: CSDN 作者: weixin_44857975 链接: https:/

189. Rotate Array

我是研究僧i 提交于 2020-02-24 05:49:42
Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Note: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? My idea:pop insert 投机了 class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place

20190901拼多多和腾讯

跟風遠走 提交于 2020-02-22 17:52:22
好几道排序的题目 PDD(手机里有题目) # 优先偶数的有序TopN(AC) def QuickSort(array,left,right): # 递归的退出条件 if left >= right: return temp = array[left] i = left j = right while i<j: while array[j]>temp and i<j: j -= 1 if array[j]<temp: array[i] = array[j] i += 1 while array[i]<temp and i<j: i += 1 if array[i]>temp: array[j] = array[i] j -= 1 array[i] = temp QuickSort(array,left,i-1) QuickSort(array,i+1,right) def topN(lst,N): lst_a = [] lst_b = [] for item in lst: if item%2 == 0: lst_a.append(item) if item%2 != 0: lst_b.append(item) print("偶数:",lst_a) print("奇数:",lst_b) QuickSort(lst_a,0,len(lst_a)-1) QuickSort(lst_b,0

Javascript深拷贝

风格不统一 提交于 2020-02-22 14:05:14
var oOriginal = { memNum: 1, // number memStr: "I am a string", // string memObj: { test1: "Old value" // we’ll test }, memArr: [ // array "a string", // string member of array { // object member of array test2: "Try changing me" // we'll test } ] }; 这是一个比较复 是一个比较复杂的对象,对象包含着对象与数组。我们用Prototype著名的继承函数复杂一下。它那个东东实在很难说是继承,jQuery的也不算。 var extend = function(result, source) { for (var key in source) result[key] = source[key]; return result; } var oCopy = extend({},oOriginal); // 浅拷贝 oCopy.memObj.test1 = "New value"; // 出现问题了,会反射到原对象上 alert(oOriginal.memObj.test1); // 结果副本与原本都一同被修改了 oCopy.memArr[1]

剑指Offer——和为S的两个数字

孤者浪人 提交于 2020-02-22 07:46:38
题目描述: 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。 输入描述: 对应每个测试案例,输出两个数,小的先输出。 分析: 如果有多对数字的和等于S,输出两个数的乘积最小的。 假设这两个数为a,b(a<b)。 a+b=S,为使a*b最小,那么a,b离得越远越好。 因为数组是递增排序的,设置两个指针,指向一头一尾,往中间夹逼。 如果和的结果大于S,那么右边的指针左移。 如果和的结果小于S,那么左边的指针右移。 代码: 1 class Solution { 2 public: 3 vector<int> FindNumbersWithSum(vector<int> array, int sum) { 4 vector<int> res; 5 int aSize = array.size(); 6 if(aSize < 2) return res; 7 int left = 0; 8 int right = aSize - 1; 9 while(left < right) { 10 if(array[left] + array[right] == sum) { 11 res.push_back(array[left]); 12 res.push_back(array[right]); 13 break;

php函数 array_diff

∥☆過路亽.° 提交于 2020-02-22 05:34:00
array_diff ( array $array1 , array $array2 [, array $... ] ) : array 对比 array1 和其他一个或者多个数组,返回在 array1 中但是不在其他 array 里的值。 <?php /** * Created by PhpStorm. * User: mac * Date: 2019/4/13 * Time: 09:37 */ /** * array_diff ( array $array1 , array $array2 [, array $... ] ) : array 对比 array1 和其他一个或者多个数组,返回在 array1 中但是不在其他 array 里的值。 */ $arr1 = [1,3,4,6,9]; //比如修改用户权限 新加的权限 $arr2 = [2,3,6,8,10]; // 旧有的权限 echo "<pre>"; print_r(array_diff($arr1,$arr2)); //最新的需要插入的权限 print_r(array_diff($arr2,$arr1)); //需要删除的旧有的,比当前提交过来的权限多的/**************************************************/ $arr1 = [1,3,4,6,9]; /

PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数的小问题

折月煮酒 提交于 2020-02-22 05:31:11
  求两个数组的交集问题可以使用array_intersect(),array_inersect_assoc,array_intersect_key来实现,其中array_intersect()函数是求两个数的交集,返回一个交集共有元素的数组(只是数组值得比较)、array_intersect_assoc()函数是将键值和值绑定,一起比较交集部分、array_intersect_key()函数是将两个数组的键值进行比较,返回键值交集的数组。   但实际应用中也遇到了一些小问题,正如下:   实例: <?PHP $array = array("red"=>"Red","green"=>"red4","Red15"=>"Red",7=>"Level","Width"=>"Red","azzzz1"=>"art","peak"=>158); $array1 = array("red"=>"Red2","greena"=>"red","Red15"=>"Red",7=>"Level","Width"=>"Red","azzzz"=>"art","peak"=>158); $num = array_intersect($array,$array1); print_r ($num); echo "<br />"; $num = array_intersect_assoc($array,