array

Leetcode刷题笔记(一)

时光毁灭记忆、已成空白 提交于 2020-01-06 10:39:35
654. Maximum Binary Tree Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. The left subtree is the maximum tree constructed from left part subarray divided by the maximum number. The right subtree is the maximum tree constructed from right part subarray divided by the maximum number. Construct the maximum tree by the given array and output the root node of this tree. ------------------------------------------------------------------------------------------------------------------ 给定一个没有重复的整数数组。

np.expand_dims的使用

我怕爱的太早我们不能终老 提交于 2020-01-04 21:14:12
关于np.expand_dims的使用,网上好多举了一些实例,自己在平时也常见,但总是有点迷糊,我知道它的作用是扩展一个张量的维度,但结果是如何变化得到的,想来想去不是太明了,所以去函数源码看了一下,算是明白了,np.expand_dims的源码如下: def expand_dims(a, axis): """ Expand the shape of an array. Insert a new axis that will appear at the `axis` position in the expanded array shape. .. note:: Previous to NumPy 1.13.0, neither ``axis < -a.ndim - 1`` nor ``axis > a.ndim`` raised errors or put the new axis where documented. Those axis values are now deprecated and will raise an AxisError in the future. Parameters ---------- a : array_like Input array. axis : int Position in the expanded axes where the new

Recursion - trying to understand

落花浮王杯 提交于 2020-01-04 17:50:24
问题 I have the next method: public static int maxFind(int [] a, int length) { if (length == 1){ return a[0]; } // recursively maxFind method on length-1 int result = maxFind(a, length - 1); if (a[length - 1] > result) return a[length - 1]; else return result; } I've finished that work, and pass some time from when i saw a tutorial of that method and i always forget the idea of recursion. i think that if someone will explain me every step of this method - i will get the idea once for all. Example

js函数中的apply()、call()、bind()方法

我的未来我决定 提交于 2020-01-04 05:46:39
1. 什么是类数组ArrayLike 拥有length属性,其它属性(索引)为非负整数(对象中的索引会被当做字符串来处理,这里你可以当做是个非负整数串来理解) 不具有数组所具有的方法 //类数组示例 var a = {'1':'gg','2':'love','4':'meimei',length:5}; Array.prototype.join.call(a,'+');//'+gg+love++meimei' //非类数组示例 var c = {'1':2}; //没有length属性就不是类数组 javascript中常见的类数组有 arguments 对象和DOM方法的返回结果。 比如 document.getElementsByTagName() 。 2. 判断一个对象是否属于类数组 function isArrayLike(o) { if (o && // o is not null, undefined, etc. typeof o === 'object' && // o is an object isFinite(o.length) && // o.length is a finite number o.length >= 0 && // o.length is non-negative o.length===Math.floor(o.length) && // o

javascript 详解数组

依然范特西╮ 提交于 2020-01-04 05:42:45
概念 数组创建 数组读写 数组 VS. 一般对象 相同点 不同点 稀疏数组 数组的length属性 元素增删 数组迭代 二维数组 数组方法 Array.prototype.join Array.prototype.reverse Array.prototype.sort Array.prototype.concat Array.prototype.slice 切片 Array.prototype.splice 胶接 Array.prototype.forEach (ES5) Array.prototype.map (ES5) Array.prototype.filter (ES5) Array.prototype.every (ES5) Array.prototype.some (ES5) Array.prototype.reduce/reduceRight (ES5) Array.prototype.indexOf/lastIndexOf (ES5) Array.isArray (ES5) 字符串和数组 最近在学习数组,发现很多ES5的方法平时很少用到。细节比较多,自己做了大量例子和整理,希望对大家了解JavaScript中的Array有所帮助。 概念 数组是值的有序集合。每个值叫做元素,每个元素在数组中都有数字位置编号,也就是索引。JS中的数组是弱类型的

JS数组学习笔记

拥有回忆 提交于 2020-01-04 05:42:19
原文: JS数组学习笔记 最近在备课数组,发现很多ES5的方法平时很少用到。细节比较多,自己做了大量例子和整理,希望对大家了解JavaScript中的Array有所帮助。 概念 数组是值的有序集合。每个值叫做元素,每个元素在数组中都有数字位置编号,也就是索引。JS中的数组是弱类型的,数组中可以含有不同类型的元素。数组元素甚至可以是对象或其它数组。 JS引擎一般会优化数组,按索引访问数组常常比访问一般对象属性明显迅速。 数组长度范围 from 0 to 4,294,967,295(2^23 - 1) 数组创建 var BAT = ['Alibaba', 'Tencent', 'Baidu']; var students = [{name : 'Bosn', age : 27}, {name : 'Nunnly', age : 3}]; var arr = ['Nunnly', 'is', 'big', 'keng', 'B', 123, true, null]; var arrInArr = [[1, 2], [3, 4, 5]]; var commasArr1 = [1, , 2]; // 1, undefined, 2 var commasArr2 = [,,]; // undefined * 2 var arr = new Array(); var arrWithLength

算法系列-计数排序

邮差的信 提交于 2020-01-03 05:01:20
计数排序是一种算法复杂度 O(n) 的排序方法,适合于小范围集合的排序。比如100万学生参加高考,我们想对这100万学生的数学成绩(假设分数为0到100)做个排序。我们如何设计一个最高效的排序算法。本文不光给出计数排序算法的传统写法,还将一步步深入讨论算法的优化,直到时间复杂度和空间复杂度最优。 先看看计数排序的定义 Counting sort (sometimes referred to as ultra sort or math sort [1] ) is a sorting algorithm which (like bucket sort ) takes advantage of knowing the range of the numbers in the array to be sorted (array A ). It uses this range to create an array C of this length. Each index i in array C is then used to count how many elements in A have the value i ; then counts stored in C can then be used to put the elements in A into their right

js算法

ε祈祈猫儿з 提交于 2020-01-03 04:57:39
1.1 原始人冒泡排序 function bubbleSort(arr) {   var len = arr.length;   for (var i = 0; i < len; i++) {     for (var j = 0; j < len - 1 - i; j++) {       if (arr[j] > arr[j+1]) { //相邻元素两两对比         var temp = arr[j+1]; //元素交换         arr[j+1] = arr[j];         arr[j] = temp;       }     }   }   return arr; } var arr=[3,44,38,5,47,15,36,26,27,2,46,4,19,50,48]; console.log(bubbleSort(arr));//[2, 3, 4, 5, 15, 19, 26, 27, 36, 38, 44, 46, 47, 48, 50] ; 这种算法不多说,有点变成基础的人都能看明白,可以说是“傻瓜排序” 1.2进化版冒泡排序 function bubbleSort2(arr) {   console.time('改进后冒泡排序耗时');   var i = arr.length-1; //初始时,最后位置保持不变     while ( i>

学习笔记之NumPy

我的梦境 提交于 2020-01-03 02:36:15
NumPy — NumPy http://www.numpy.org/ NumPy is the fundamental package for scientific computing with Python. NumPy - Wikipedia https://en.wikipedia.org/wiki/NumPy NumPy (pronounced / ˈ n ʌ m p aɪ/ ( NUM-py ) or sometimes / ˈ n ʌ m p i/ [1] [2] ( NUM-pee )) is a library for the Python programming language , adding support for large, multi-dimensional arrays and matrices , along with a large collection of high-level mathematical functions to operate on these arrays. The ancestor of NumPy, Numeric, was originally created by Jim Hugunin with contributions from several other developers. In 2005,

numpy 学习笔记

孤街醉人 提交于 2020-01-03 02:36:03
numpy 学习笔记 导入 numpy 包 import numpy as np 声明 ndarray 的几种方法 方法一,从list中创建 l = [[1,2,3], [4,5,6], [7,8,9]] matrix = np.array(l) print(matrix) [[1 2 3] [4 5 6] [7 8 9]] 方法二,指定维度,不赋值 matrix = np.ndarray(shape=(3,4)) print(matrix) [[9.66308774e-312 2.47032823e-322 0.00000000e+000 0.00000000e+000] [1.89146896e-307 2.42336543e-057 5.88854416e-091 9.41706373e-047] [5.44949034e-067 1.46609735e-075 3.99910963e+252 3.43567991e+179]] 由上述的输出可见,矩阵内部的值未初始化,其实这都是原来对应内存地址中的数值 方法三,指定维度,初始化成全零的矩阵 matrix = np.zeros(shape=[3,4]) print(matrix) [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]] 方法四,使用默认参数,赋值成从0至arange的一组数