array

JS基础之 数组

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 13:59:45
数组:数组是使用单独变量名来存储一系列相同数据类型的值。 一维数组:①空数组:var 变量名= new Array();/ var 变量名=【】 ;,var 变量名=new Array(数组长度);      ②有数值的数组: var 变量名 =new Array("1""2");/ var 变量名=【1,2,3】; 注意: var arr1 = [3]; // arr1.length == 1, arr1[0] == 3 var arr2 = new Array(3); // arr2.length == 3, arr2[0] == undefined 多维数组: var twoArray = new Array(); twoArray[0] = new Array();// 数组index=0之中又new一个数组 twoArray[1] = new Array();// 数组index=1之中又new一个数组 // 构建twoArray[0]数组 twoArray[0][0] = "aa"; twoArray[0][1] = "ba"; twoArray[0][3] = "ca"; // 构建twoArray[1]数组 twoArray[1][0] = "acca"; twoArray[1][1] = "bada"; twoArray[1][3] = "cdasa"; var

[leetcode note] 3Sum Closest

折月煮酒 提交于 2019-12-17 02:40:27
时间: 2019-12-16 8:14 PM 题目地址: https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. 给定一个已排序的数组num,原地删除重复项,以使每个元素仅出现一次并返回新的长度。 不要为另一个数组分配额外的空间,必须通过使用O(1)额外的内存就地修改输入数组来做到这一点。 Example 1: Given nums = [ 1 , 1 , 2 ] , Your function should return length = 2 , with the first two elements of nums being 1 and 2 respectively . It doesn't matter

Python库学习-Numpy

谁说我不能喝 提交于 2019-12-17 01:38:39
文章目录 1、数组的创建与操作 1.1 数组创建 1.2 数组元素获取 1.3 数组的常用属性 2、数组的基本运算符 2.1 广播运算 3、常用的数学和统计函数 4、线性代数的相关计算 4.1 特征根与特征向量 4.2 多元线性回归模型的解 4.3 多元一次方程组的求解 Python的数值运算模块Numpy,通过numpy模块的学习,你将掌握如下几方面的内容: 数组的创建与操作; 数组的基本数学运算; 常用数学和统计函数; 线性代数的求解; 伪随机数的创建。 1、数组的创建与操作 Numpy的数据类型为ndarray,通过array函数创建数组: 1.1 数组创建 import numpy as np # 一维数组 arr1 = np . array ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) # 二维数组 arr2 = np . array ( [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ) ''' array([1, 2, 3, 4, 5, 6]) array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) ''' 1.2 数组元素获取 arr2 [ 1 , 1 ] arr2 [ 1 : , 1 : ] arr2 [ [ 0 , 2 ] , [ 0 , 2 ] ] ''' 5

素数环问题_JAVA实现_回溯法

别来无恙 提交于 2019-12-16 22:09:44
具体说明请看代码中的注释。 个人实现,如有Bug请指正。 /** * @Author = The Great Ke * @description: 素数环问题———— 采用回溯法 * @Date: Creat in 20:01 2019/12/16 * @modified by : */ public class SuShuHuan_Pro { //判断某整数是不是质数 public static boolean isp(int n){ for(int i = 2; i < Math.sqrt(n)+1;i++){ if(n % i == 0){ return false; } } return true; } public static int n = 6; public static boolean[] is_Used = new boolean[n+1];//存储某数是否被使用 public static int[] array = new int[n+1];//存放数列 public static void dfs(int cur){ if(cur == n+1 && isp(array[1]+ array[n]) && array[1] == 1){//如果最后一个数放进去了,并且最后一个数和第一个的和为质数,并且第一个数是1(因为我们只输出开头是1的,避免重复) for

S07

↘锁芯ラ 提交于 2019-12-16 10:48:45
push 和 append 的表现不同, push 一次只添加单个参数到列表末端, append 一次可以添加多个参数。 use v6; my @d = ( [ 1 .. 3 ] ); @d.push( [ 4 .. 6 ] ); @d.push( [ 7 .. 9 ] ); for @d -> $r { say "$r[]"; } # 1 # 2 # 3 # 4 5 6 # 7 8 9 for @d -> $r { say $r.WHAT() } # (Int) # (Int) # (Int) # (Array) 整个数组作为单个参数 # (Array) say @d.perl; # [1, 2, 3, [4, 5, 6], [7, 8, 9]] 使用 append 一次能追加多个元素: use v6; my @d = ( [ 1 .. 3 ] ); @d.append( [ 4 .. 6 ] ); @d.append( [ 7 .. 9 ] ); for @d -> $item { say "$item[]"; } # 打印 1n2n3n4n5n6n7n8n9 # [1, 2, 3, 4, 5, 6, 7, 8, 9] 这跟 The single argument rule 有关。 设计大纲 Perl 6 提供了很多跟列表相关的特性, 包括 eager , lazy ,

javaScript数组的api

╄→尐↘猪︶ㄣ 提交于 2019-12-16 08:37:15
1、pop() pop() 方法删除一个数组中的最后的一个元素,并且返回这个元素。 var array = [1, 2, 3, 4, 5]; var item = array.pop(); console.log(array); // [1, 2, 3, 4] console.log(item); // 4 会影响原数组的内容 2、push push()方法添加一个或者多个元素到数组末尾,并且返回数组新的长度。 var array = [1,2,3,4,5]; var i = array.push(6); console.log(array); // [1,2,3,4,5,6] console.log(i); // 6 3、reverse reverse()方法颠倒数组中元素的位置,第一个会成为最后一个,最后一个会成为第一个,该方法返回对数组的引用。 var array = [1,2,3,4,5]; var array2 = array.reverse(); console.log(array); // [5,4,3,2,1] console.log(array2===array); // true 3、shift shift()方法删除数组的第一个元素,并返回这个元素。如果是栈的话,这个过程就是栈底弹出。 var array = [1,2,3,4,5]; var item =

Codeforces Round #605 (Div. 3) D. Remove One Element(DP)

为君一笑 提交于 2019-12-15 23:59:34
链接: https://codeforces.com/contest/1272/problem/D 题意: You are given an array a consisting of n integers. You can remove at most one element from this array. Thus, the final length of the array is n−1 or n. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray a with indices from l to r is a[l…r]=al,al+1,…,ar. The subarray a[l…r] is called strictly increasing if al<al+1<⋯<ar. 思路: 正着反着算一边,能往两边延长的最大长度,对每个点特判。 代码: #include<bits/stdc++.h> using namespace std; const int MAXN = 2e5+10; int Dp

【Python学习之路】Numpy 结构化数组

℡╲_俬逩灬. 提交于 2019-12-15 22:04:27
结构化数组 假设我们要保存这样的数据: name age wgt 0 dan 1 1 ann 0 2 sam 2 希望定义一个一维数组,每个元素有三个属性 name, age, wgt ,此时我们需要使用结构化数组。 import numpy as np 定义数组 a : 0 1 2 3 1.0 2.0 3.0 4.0 a = np . array ( [ 1.0 , 2.0 , 3.0 , 4.0 ] , np . float32 ) 使用 view 方法,将 a 对应的内存按照复数来解释: a . view ( np . complex64 ) array([ 1.+2.j, 3.+4.j], dtype=complex64) 0 1 2 3 1.0 2.0 3.0 4.0 real imag real imag 事实上,我们可以把复数看成一个结构体,第一部分是实部,第二部分是虚部,这样这个数组便可以看成是一个结构化数组。 换句话说,我们只需要换种方式解释这段内存,便可以得到结构化数组的效果! 0 1 2 3 1.0 2.0 3.0 4.0 mass vol mass vol 例如,我们可以将第一个浮点数解释为质量,第二个浮点数解释为速度,则这段内存还可以看成是包含两个域(质量和速度)的结构体。 my_dtype = np . dtype ( [ ( 'mass' ,

【Python学习之路】Numpy 二元运算

不问归期 提交于 2019-12-15 22:03:00
二元运算 import numpy as np 四则运算 运算 函数 a + b add(a,b) a - b subtract(a,b) a * b multiply(a,b) a / b divide(a,b) a ** b power(a,b) a % b remainder(a,b) 以乘法为例,数组与标量相乘,相当于数组的每个元素乘以这个标量: a = np . array ( [ 1 , 2 ] ) a * 3 array([3, 6]) 数组逐元素相乘: a = np . array ( [ 1 , 2 ] ) b = np . array ( [ 3 , 4 ] ) a * b array([3, 8]) 使用函数: np . multiply ( a , b ) array([3, 8]) 事实上,函数还可以接受第三个参数,表示将结果存入第三个参数中: np . multiply ( a , b , a ) array([3, 8]) a array([3, 8]) 比较和逻辑运算 运算 函数< == equal != not_equal > greater >= greater_equal < less <= less_equal logical_and logical_or logical_xor logical_not & bitwise_and

数组Array.Sort()和Array.Reverse()的使用方法

本秂侑毒 提交于 2019-12-15 03:40:12
Array.Sort() int[] arr = new int[] {19,3,9,6,7,5,8 }; Array.Sort(arr); foreach (var item in arr) { Console.Write(" "+item); } //////打印结果为:3 5 6 7 8 9 19 Array.Reverse() int[] arr = new int[] {19,3,9,6,7,5,8 }; Array.Reverse(arr); foreach (var item in arr) { Console.Write(" "+item); } //////打印结果为: 8 5 7 6 9 3 19 注意:Array.Reverse()的方法的意思就是把数字反过来搞一遍,不是用来比较大小数的 来源: CSDN 作者: User:你的影子 链接: https://blog.csdn.net/weixin_44831306/article/details/103455398