-
关于python的列表以下选项中描述错误的是_以下关于Python列表的描述中,错误的是______...
2021-01-14 02:11:05以下关于Python列表的描述中,错误的是______答:列表的长度和内容都可以改变,但元素类型必须相同Which of the following statements is NOT true about the word ‘typical’?答:It means ‘nice’.调节酸碱平衡...以下关于Python列表的描述中,错误的是______
答:列表的长度和内容都可以改变,但元素类型必须相同
Which of the following statements is NOT true about the word ‘typical’?
答:It means ‘nice’.
调节酸碱平衡最重要的器官
答:肾
《三国演义》中貂蝉最后的结局是什么?
答:下落不明
人们日常的最主要的表情语是指()。
答:目光和笑态
心流的状态只有顶级优秀的人物才能达成
答:错
心衰B段是指合并基础心血管疾病,如高血压、冠心病和糖尿病,具有发生心衰风险的患者
答:×
某企业计划投资10万元建一条生产线,预计投资后每年可获净利1.5万元,年折旧率为10%,则静态投资回收期为年
答:4
目前认为核被膜破裂是由于:
答:核纤层蛋白去磷酸化
患者女性,21岁,坠楼后额部着地,确诊为颅底骨折。首选治疗措施是
答:保守治疗
优学院: 如果在社会生活中,把一切都看作是必然的,就会导致命运决定一切的( )。
答:唯心主义宿命论
中国大学MOOC: Choose the correct phrases or sentences to complete the sentences. Nature’s recycling system can work well only if people work with the system, ____ against it.
答:rather than
《情书》的导演是____
答:岩井俊二
如果某商品富有需求的价格弹性,则该商品价格上升( )
答:会使该商品销售收益下降
营销渠道管理是企业内部的管理活动
答:×
维新运动及其历史意义和教训?
答:戊戌变法的历史意义\n(1)资产阶级改良运动,符合中国历史发展趋势,具有进步意义.\n(2)爱国救亡运动,激发了人民的爱国思想和民族意识.\n(3)近代中国第一次思想解放的潮流.在社会上起了思想启蒙作用,促进了中国人民的觉醒。\n教训:在当时的中国,改良主义的道路是走不通的,中国近代化的路程是漫长而又坎坷的.
在定值保险中,保险赔款与被保险人的实际损失的关系是
答:保险赔款可能超过实际损失
What is the musical form of Bolero?
答:One movement
通常母乳中含量不足的营养素是
答:铁
风险管理的基础是
答:风险识别
出头教育: In August 1977, a satellite\nto gather data about the 10 million black holes which are thought to be in the Milky Way.
答:was launched
-
剑指offer_第1题_二维数组中的查找
2018-08-22 14:09:24在一个二维数组中(每个一维数组的长度相同) 每一行都按照从左到右递增的顺序排序 每一列都按照从上到下递增的顺序排序。 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 理解 ...题目描述
- 在一个二维数组中(每个一维数组的长度相同)
- 每一行都按照从左到右递增的顺序排序
- 每一列都按照从上到下递增的顺序排序。
请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
理解
- 什么是二维数组?
实际上python当中没有数组的概念, 而是列表(List), 二维列表相当于二维数组 。
python中创建二维数组
import numpy as np array = np.array([[1,2,3],[4,5,6],[7,8,9]])
[[1 2 3] [4 5 6] [7 8 9]]
- 数组和矩阵的区别?
python基础–数组和矩阵区别
数组和矩阵区别
解题思路
思路1
直接循环遍历每一个元素,判断是否等于给定的整数,如果相等则输出存在,否则不存在class Solution: # array 二维列表 def Find(self, target, array): for i in range(len(array)): for j in range(len(array[0])): if array[i][j] == target: return True return False
思路2
由于数组元素是分别按行按列递增的,故可以:- 从最后一行第一列开始遍历
记给定的整数为target
,数组元素为array[i][j]
如果 target < array[i][j] 则行数减1
如果 target > array[i][j] 则列数加1
如果 target == array[i][j] 则返还True
class Solution: # array 二维列表 def Find(self, target, array): row = len(array) - 1 col = len(array[0]) - 1 i = row j = 0 while i >= 0 and j <= col: if target < array[i][j]: i = i - 1 elif target > array[i][j]: j = j + 1 else: return True
-
Redis源码分析(六)--- ziplist压缩列表
2014-10-11 15:05:08而今天的ziplist指的是压缩链表,为什么叫压缩链表呢,因为链表中我们一般常用pre,next来指明当前的结点的前一个指针或当前的结点的下一个指针,这其实是在一定程度上占据了比较多的内存空间,ziplist采用了长度的...ziplist和之前我解析过的adlist列表名字看上去的很像,但是作用却完全不同。之前的adlist主要针对的是普通的数据链表操作。而今天的ziplist指的是压缩链表,为什么叫压缩链表呢,因为链表中我们一般常用pre,next来指明当前的结点的前一个指针或当前的结点的下一个指针,这其实是在一定程度上占据了比较多的内存空间,ziplist采用了长度的表示方法,整个ziplist其实是超级长的字符串,通过里面各个结点的长度,上一个结点的长度等信息,通过快速定位实现相关操作,而且编写者,在长度上也做了动态分配字节的方法,表示长度,避免了一定的内存耗费,比如一个结点的字符串长度每个都很短,而你使用好几个字节表示字符串的长度,显然造成大量浪费,所以在长度表示方面,ziplist 就做到了压缩,也体现了压缩的性能。ziplist 用在什么地方呢,ziplist 就是用在我们平常最常用的一个命令rpush,lpush等这些往链表添加数据的方法,这些数据就是存在ziplist 中的。之后我们会看到相应的实现方法。
在学习ziplist的开始,一定要理解他的结构,关于这一点,必须花一定时间想想,要不然不太容易明白人家的设计。下面是我的理解,帮助大家理解:
/* The ziplist is a specially encoded dually linked list that is designed * to be very memory efficient. It stores both strings and integer values, * where integers are encoded as actual integers instead of a series of * characters. It allows push and pop operations on either side of the list * in O(1) time. However, because every operation requires a reallocation of * the memory used by the ziplist, the actual complexity is related to the * amount of memory used by the ziplist. * * ziplist是一个编码后的列表,特殊的设计使得内存操作非常有效率,此列表可以同时存放 * 字符串和整数类型,列表可以在头尾各边支持推加和弹出操作在O(1)常量时间,但是,因为每次 * 操作设计到内存的重新分配释放,所以加大了操作的复杂性 * ---------------------------------------------------------------------------- * * ziplist的结构组成: * ZIPLIST OVERALL LAYOUT: * The general layout of the ziplist is as follows: * <zlbytes><zltail><zllen><entry><entry><zlend> * * <zlbytes> is an unsigned integer to hold the number of bytes that the * ziplist occupies. This value needs to be stored to be able to resize the * entire structure without the need to traverse it first. * <zipbytes>代表着ziplist占有的字节数,这方便当重新调整大小的时候不需要重新从头遍历 * * <zltail> is the offset to the last entry in the list. This allows a pop * operation on the far side of the list without the need for full traversal. * <zltail>记录了最后一个entry的位置在列表中,可以方便快速在列表末尾弹出操作 * * <zllen> is the number of entries.When this value is larger than 2**16-2, * we need to traverse the entire list to know how many items it holds. * <zllen>记录的是ziplist里面entry数据结点的总数 * * <zlend> is a single byte special value, equal to 255, which indicates the * end of the list. * <zlend>代表的是结束标识别,用单字节表示,值是255,就是11111111 * * ZIPLIST ENTRIES: * Every entry in the ziplist is prefixed by a header that contains two pieces * of information. First, the length of the previous entry is stored to be * able to traverse the list from back to front. Second, the encoding with an * optional string length of the entry itself is stored. * 每个entry数据结点主要包含2部分信息,第一个,上一个结点的长度,主要就可以可以从任意结点从后往前遍历整个列表 * 第二个,编码字符串的方式的类型保存 * * The length of the previous entry is encoded in the following way: * If this length is smaller than 254 bytes, it will only consume a single * byte that takes the length as value. When the length is greater than or * equal to 254, it will consume 5 bytes. The first byte is set to 254 to * indicate a larger value is following. The remaining 4 bytes take the * length of the previous entry as value. * 之前的数据结点的字符串长度的长度少于254个字节,他将消耗单个字节,一个字节8位,最大可表示长度为2的8次方 * 当字符串的长度大于254个字节,则用5个字节表示,第一个字节被设置成254,其余的4个字节占据的长度为之前的数据结点的长度 * * The other header field of the entry itself depends on the contents of the * entry. When the entry is a string, the first 2 bits of this header will hold * the type of encoding used to store the length of the string, followed by the * actual length of the string. When the entry is an integer the first 2 bits * are both set to 1. The following 2 bits are used to specify what kind of * integer will be stored after this header. An overview of the different * types and encodings is as follows: * 头部信息中的另一个值记录着编码的方式,当编码的是字符串,头部的前2位为00,01,10共3种 * 如果编码的是整型数字的时候,则头部的前2位为11,代表的是整数编码,后面2位代表什么类型整型值将会在头部后面被编码 * 00-int16_t, 01-int32_t, 10-int64_t, 11-24 bit signed,还有比较特殊的2个,11111110-8 bit signed, * 1111 0000 - 1111 1101,代表的是整型值0-12,头尾都已经存在,都不能使用,与传统的通过固定的指针表示长度,这么做的好处实现 * 可以更合理的分配内存 * * String字符串编码的3种形式 * |00pppppp| - 1 byte * String value with length less than or equal to 63 bytes (6 bits). * |01pppppp|qqqqqqqq| - 2 bytes * String value with length less than or equal to 16383 bytes (14 bits). * |10______|qqqqqqqq|rrrrrrrr|ssssssss|tttttttt| - 5 bytes * String value with length greater than or equal to 16384 bytes. * |11000000| - 1 byte * Integer encoded as int16_t (2 bytes). * |11010000| - 1 byte * Integer encoded as int32_t (4 bytes). * |11100000| - 1 byte * Integer encoded as int64_t (8 bytes). * |11110000| - 1 byte * Integer encoded as 24 bit signed (3 bytes). * |11111110| - 1 byte * Integer encoded as 8 bit signed (1 byte). * |1111xxxx| - (with xxxx between 0000 and 1101) immediate 4 bit integer. * Unsigned integer from 0 to 12. The encoded value is actually from * 1 to 13 because 0000 and 1111 can not be used, so 1 should be * subtracted from the encoded 4 bit value to obtain the right value. * |11111111| - End of ziplist. * * All the integers are represented in little endian byte order. * * ----------------------------------------------------------------------------
希望大家能仔细反复阅读,理解作者的设计思路,下面给出的他的实际结构体的定义:/* 实际存放数据的数据结点 */ typedef struct zlentry { //prevrawlen为上一个数据结点的长度,prevrawlensize为记录该长度数值所需要的字节数 unsigned int prevrawlensize, prevrawlen; //len为当前数据结点的长度,lensize表示表示当前长度表示所需的字节数 unsigned int lensize, len; //数据结点的头部信息长度的字节数 unsigned int headersize; //编码的方式 unsigned char encoding; //数据结点的数据(已包含头部等信息),以字符串形式保存 unsigned char *p; } zlentry; /* <zlentry>的结构图线表示 <pre_node_len>(上一结点的长度信息)<node_encode>(本结点的编码方式和编码数据的长度信息)<node>(本结点的编码数据) */
我们看一下里面比较核心的操作,插入操作,里面涉及指针的各种来回移动,这些都是内存地址的调整:/* Insert item at "p". */ /* 插入操作的实现 */ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen) { size_t curlen = intrev32ifbe(ZIPLIST_BYTES(zl)), reqlen; unsigned int prevlensize, prevlen = 0; size_t offset; int nextdiff = 0; unsigned char encoding = 0; long long value = 123456789; /* initialized to avoid warning. Using a value that is easy to see if for some reason we use it uninitialized. */ zlentry tail; /* Find out prevlen for the entry that is inserted. */ //寻找插入的位置 if (p[0] != ZIP_END) { //定位到指定位置 ZIP_DECODE_PREVLEN(p, prevlensize, prevlen); } else { //如果插入的位置是尾结点,直接定位到尾结点,看第一个字节的就可以判断 unsigned char *ptail = ZIPLIST_ENTRY_TAIL(zl); if (ptail[0] != ZIP_END) { prevlen = zipRawEntryLength(ptail); } } /* See if the entry can be encoded */ if (zipTryEncoding(s,slen,&value,&encoding)) { /* 'encoding' is set to the appropriate integer encoding */ reqlen = zipIntSize(encoding); } else { /* 'encoding' is untouched, however zipEncodeLength will use the * string length to figure out how to encode it. */ reqlen = slen; } /* We need space for both the length of the previous entry and * the length of the payload. */ reqlen += zipPrevEncodeLength(NULL,prevlen); reqlen += zipEncodeLength(NULL,encoding,slen); /* When the insert position is not equal to the tail, we need to * make sure that the next entry can hold this entry's length in * its prevlen field. */ nextdiff = (p[0] != ZIP_END) ? zipPrevLenByteDiff(p,reqlen) : 0; /* Store offset because a realloc may change the address of zl. */ //调整大小,为新结点的插入预留空间 offset = p-zl; zl = ziplistResize(zl,curlen+reqlen+nextdiff); p = zl+offset; /* Apply memory move when necessary and update tail offset. */ if (p[0] != ZIP_END) { /* Subtract one because of the ZIP_END bytes */ //如果插入的位置不是尾结点,则挪动位置 memmove(p+reqlen,p-nextdiff,curlen-offset-1+nextdiff); /* Encode this entry's raw length in the next entry. */ zipPrevEncodeLength(p+reqlen,reqlen); /* Update offset for tail */ ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+reqlen); /* When the tail contains more than one entry, we need to take * "nextdiff" in account as well. Otherwise, a change in the * size of prevlen doesn't have an effect on the *tail* offset. */ tail = zipEntry(p+reqlen); if (p[reqlen+tail.headersize+tail.len] != ZIP_END) { ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+nextdiff); } } else { //如果是尾结点,直接设置新尾结点 /* This element will be the new tail. */ ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe(p-zl); } /* When nextdiff != 0, the raw length of the next entry has changed, so * we need to cascade the update throughout the ziplist */ if (nextdiff != 0) { offset = p-zl; zl = __ziplistCascadeUpdate(zl,p+reqlen); p = zl+offset; } /* Write the entry */ //写入新的数据结点信息 p += zipPrevEncodeLength(p,prevlen); p += zipEncodeLength(p,encoding,slen); if (ZIP_IS_STR(encoding)) { memcpy(p,s,slen); } else { zipSaveInteger(p,value,encoding); } //更新列表的长度加1 ZIPLIST_INCR_LENGTH(zl,1); return zl; }
下面是删除操作:/* Delete "num" entries, starting at "p". Returns pointer to the ziplist. */ /* 删除方法涉及p指针的滑动,后面的地址内容都需要滑动 */ static unsigned char *__ziplistDelete(unsigned char *zl, unsigned char *p, unsigned int num) { unsigned int i, totlen, deleted = 0; size_t offset; int nextdiff = 0; zlentry first, tail; first = zipEntry(p); for (i = 0; p[0] != ZIP_END && i < num; i++) { p += zipRawEntryLength(p); deleted++; } totlen = p-first.p; if (totlen > 0) { if (p[0] != ZIP_END) { /* Storing `prevrawlen` in this entry may increase or decrease the * number of bytes required compare to the current `prevrawlen`. * There always is room to store this, because it was previously * stored by an entry that is now being deleted. */ nextdiff = zipPrevLenByteDiff(p,first.prevrawlen); p -= nextdiff; zipPrevEncodeLength(p,first.prevrawlen); /* Update offset for tail */ ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))-totlen); /* When the tail contains more than one entry, we need to take * "nextdiff" in account as well. Otherwise, a change in the * size of prevlen doesn't have an effect on the *tail* offset. */ tail = zipEntry(p); if (p[tail.headersize+tail.len] != ZIP_END) { ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+nextdiff); } /* Move tail to the front of the ziplist */ memmove(first.p,p, intrev32ifbe(ZIPLIST_BYTES(zl))-(p-zl)-1); } else { /* The entire tail was deleted. No need to move memory. */ ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe((first.p-zl)-first.prevrawlen); } /* Resize and update length */ //调整列表大小 offset = first.p-zl; zl = ziplistResize(zl, intrev32ifbe(ZIPLIST_BYTES(zl))-totlen+nextdiff); ZIPLIST_INCR_LENGTH(zl,-deleted); p = zl+offset; /* When nextdiff != 0, the raw length of the next entry has changed, so * we need to cascade the update throughout the ziplist */ if (nextdiff != 0) zl = __ziplistCascadeUpdate(zl,p); } return zl; }
该方法的意思是从index索引对应的结点开始算起,删除num个结点,这是删除的最原始的方法,其他方法都是对此方法的包装。下面我们看看我们在redis命令行中输入的lpush或rpush调用的是什么方法呢?调用的形式:
zl = ziplistPush(zl, (unsigned char*)"foo", 3, ZIPLIST_TAIL); zl = ziplistPush(zl, (unsigned char*)"quux", 4, ZIPLIST_TAIL); zl = ziplistPush(zl, (unsigned char*)"hello", 5, ZIPLIST_HEAD);
/* 在列表2边插入数据的方法 */ unsigned char *ziplistPush(unsigned char *zl, unsigned char *s, unsigned int slen, int where) { unsigned char *p; //这里开始直接定位 p = (where == ZIPLIST_HEAD) ? ZIPLIST_ENTRY_HEAD(zl) : ZIPLIST_ENTRY_END(zl); //组后调用插入数据的insert方法 return __ziplistInsert(zl,p,s,slen); }
到最后还是调用了insert方法。在写之前看了一些别人分析的ziplist分析,感觉有些说的的都很粗略,还是自己仔细过一遍心里会清楚很多,建议大家多多阅读源码。每个人侧重点都是不一样的。最后给出头文件和比较关键的宏定义:
.h文件:/* zip列表的末尾值 */ #define ZIP_END 255 /* zip列表的最大长度 */ #define ZIP_BIGLEN 254 /* Different encoding/length possibilities */ /* 不同的编码 */ #define ZIP_STR_MASK 0xc0 #define ZIP_INT_MASK 0x30 #define ZIP_STR_06B (0 << 6) #define ZIP_STR_14B (1 << 6) #define ZIP_STR_32B (2 << 6) #define ZIP_INT_16B (0xc0 | 0<<4) #define ZIP_INT_32B (0xc0 | 1<<4) #define ZIP_INT_64B (0xc0 | 2<<4) #define ZIP_INT_24B (0xc0 | 3<<4) #define ZIP_INT_8B 0xfe /* 4 bit integer immediate encoding */ #define ZIP_INT_IMM_MASK 0x0f //后续的好多运算都需要与掩码进行位运算 #define ZIP_INT_IMM_MIN 0xf1 /* 11110001 */ #define ZIP_INT_IMM_MAX 0xfd /* 11111101 */ //最大值不能为11111111,这跟最末尾的结点重复了 #define ZIP_INT_IMM_VAL(v) (v & ZIP_INT_IMM_MASK) #define INT24_MAX 0x7fffff #define INT24_MIN (-INT24_MAX - 1) /* Macro to determine type */ #define ZIP_IS_STR(enc) (((enc) & ZIP_STR_MASK) < ZIP_STR_MASK) /* Utility macros */ /* 下面是一些用来到时能够直接定位的数值偏移量 */ #define ZIPLIST_BYTES(zl) (*((uint32_t*)(zl))) #define ZIPLIST_TAIL_OFFSET(zl) (*((uint32_t*)((zl)+sizeof(uint32_t)))) #define ZIPLIST_LENGTH(zl) (*((uint16_t*)((zl)+sizeof(uint32_t)*2))) #define ZIPLIST_HEADER_SIZE (sizeof(uint32_t)*2+sizeof(uint16_t)) #define ZIPLIST_ENTRY_HEAD(zl) ((zl)+ZIPLIST_HEADER_SIZE) #define ZIPLIST_ENTRY_TAIL(zl) ((zl)+intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))) #define ZIPLIST_ENTRY_END(zl) ((zl)+intrev32ifbe(ZIPLIST_BYTES(zl))-1)
/* * Copyright (c) 2009-2012, Pieter Noordhuis <pcnoordhuis at gmail dot com> * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Redis nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* 标记列表头节点和尾结点的标识 */ #define ZIPLIST_HEAD 0 #define ZIPLIST_TAIL 1 unsigned char *ziplistNew(void); //创建新列表 unsigned char *ziplistPush(unsigned char *zl, unsigned char *s, unsigned int slen, int where); //像列表中推入数据 unsigned char *ziplistIndex(unsigned char *zl, int index); //索引定位到列表的某个位置 unsigned char *ziplistNext(unsigned char *zl, unsigned char *p); //获取当前列表位置的下一个值 unsigned char *ziplistPrev(unsigned char *zl, unsigned char *p); //获取当期列表位置的前一个值 unsigned int ziplistGet(unsigned char *p, unsigned char **sval, unsigned int *slen, long long *lval); //获取列表的信息 unsigned char *ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen); //向列表中插入数据 unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p); //列表中删除某个结点 unsigned char *ziplistDeleteRange(unsigned char *zl, unsigned int index, unsigned int num); //从index索引对应的结点开始算起,删除num个结点 unsigned int ziplistCompare(unsigned char *p, unsigned char *s, unsigned int slen); //列表间的比较方法 unsigned char *ziplistFind(unsigned char *p, unsigned char *vstr, unsigned int vlen, unsigned int skip); //在列表中寻找某个结点 unsigned int ziplistLen(unsigned char *zl); //返回列表的长度 size_t ziplistBlobLen(unsigned char *zl); //返回列表的二进制长度,返回的是字节数
-
【线性代数的本质|笔记】向量究竟是什么
2020-07-17 22:20:1301-向量究竟是什么?...向量其实就是列表的另一种表达,且向量的维度就是列表的长度 数学家观点 向量可以是任何事物,只要两个被定义为向量的事物的加法与数乘运算有意义。 线性代数对向量的抽01-向量究竟是什么?
物理观点
- 向量是空间中的一个有向箭头
- 决定这个向量的是它的长度和所指的方向
- 因为长度+方向唯一地确定一个向量,因此物理学的观点中描述的向量是自由向量,可以自由平移一个向量且保持该向量不变。
CS观点
- 向量是有序的数字列表
- 在实际问题中我们往往会使用一串数字对问题进行描述和建模,且数字之间是严格有序的
- 向量其实就是列表的另一种表达,且向量的维度就是列表的长度
数学家观点
- 向量可以是任何事物,只要两个被定义为向量的事物的加法与数乘运算有意义。
线性代数对向量的抽象
- 每次讲述到向量及其相关概念时,先预想一个在坐标系中经过原点的带箭头的线段
- 有序列表——设想一个坐标系,原点则是所有向量的凝聚的核心,向量坐标就是有序列表,它是用来指导如何从原点到达箭头所在坐标点
向量的加法运算
向量加法运算——“首尾相接,首尾连”这是在线性代数中唯一出现的可以让向量离开原点的情形。
理解:把每个向量都看做是一种特定的运动,即在空间中朝着某个方向迈出一定距离
某一个点先沿着向量1运动,之后再沿着向量2运动,其效果和该点从初始位置沿着向量1与2的和运动没有差异。
向量的数乘运算
- 向量的数乘运算就相当于对向量进行放缩
运算方式即对每一个分量分别乘上缩放系数
-
线性代数的本质第一章——向量是什么
2020-06-30 11:02:52决定一个向量的是:它的长度和它所指的方向 从计算机专业学生的视角看: 向量是有序的数字列表 向量不过是“列表”一个花哨的说法 向量的维度等于“列表”的长度 从数学专业学生的视角看: 向量可以是任何东西,只... -
牛客网剑指offer在线编程01二维数组中的查找
2019-03-10 22:23:10(1) 在一个二维数组中(每个一维数组的长度相同) (2) 每一行都按照从左到右递增的顺序排序 (3)每一列都按照从上到下递增的顺序排序。 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否... -
列表和元组
2020-03-17 17:42:11什么是序列 ...此外,Python已经内置确定序列的长度以及确定最大和最小的元素的方法。 序列都可以进行的操作包括索引,切片,加,乘,检查成员。 1.什么是索引 索引从0开始,最后是-1,数据类型为整型... -
线性代数的本质(1)向量究竟是什么?
2018-06-19 09:19:07物理专业学生的视角:向量是空间中的箭头,决定一个向量的是它的长度和它所指的方向,但是只要以上两个特征相同,你可以自由移动一个向量而保持它不变。处在平面中的向量是二维的。而处在我们所生活的空间中的向量是... -
python中字符串比较是基于字典序的_python中字符串,列表,字典,元组的区别 2016-08-19...
2021-02-09 20:01:40python中遇到的一个很扰人的问题就是这些...字符串什么是字符串,就是指一串字符,在python中就像这样定义:fruit = 'banana'字符串中还有很多用法比如求字符串长度,比较字符串,循环,切割等等,由于重点不在这里... -
Redis源代码分析(六)--- ziplist压缩列表
2017-05-12 15:12:00ziplist和之前我解析过的adlist列表名字看上去的非常像。可是作用却全然不同。之前的adlist主要针对的是普通的数据链表操作。而今天的ziplist指的是压缩链表。为什么叫压缩链表呢。由于链表中我们一般经常使用pre。... -
剑指Offer14:链表中倒数第k个结点
2018-12-01 10:52:02反之,将head.val的值依次加入到列表l中,然后在判断k是否大于l的长度,若是则什么都不返回,反之返回l[-k]。 # -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.ne... -
线性代数的本质(3Blue1Brown线代笔记)
2020-06-13 17:41:59之所以是二维的是因为这个列表的长度是2。 而数学家尝试去概括上述两种观点,认为向量可以是任何东西,只要保证两个向量相加以及数字与向量相乘是有意义的即可。需要注意的是,向量加法和向量数乘贯穿线性代数始终... -
python三人同行七十稀_歌诀“三人同行七十稀,五树梅花廿一枝”与什么问题有关?()...
2020-12-24 18:30:13歌诀关下列可以用来区别烯烃和端位炔的试剂是( )技能清单法是指一个反映员工工作能力特征的一个列表,人树梅包括员工的教育背景,工作经历,培训情况,所掌握的技能,以及相应的资格证书等等。计算机语音发展的三个... -
JavaScript中的数组和字符串
2018-07-21 23:21:00数组指的是数据的有序列表,每种语言基本上都有数组这个概念,但是JavaScript的数组跟别的语言的数组很不同: 数组长度可以动态改变 同一个数组中可以存储不同的数据类型 数据的有序集合 每个数组都有一个... -
模糊的概念
2014-12-12 22:27:00java的hashMap的源码: 负载因子,到底指的是什么? 负载因子表示散表的装满程度,定义为散列表中节点的数目除以基本区域能容纳的节点数所得的商。比如说散列表长度为m,其中有n个位置已放了值,那么负载因子 a=n/m... -
JS实现判断滚动条滚到页面底部并执行事件的方法
2021-01-19 18:50:11需要了解三个dom元素,分别是:clientHeight、offsetHeight、scrollTop。...他可以理解为滚动条可以滚动的长度。 举例,如果一个DIV高度是400px(即clientHeight为400),而里面的内容是一个很长的列表,内容的高 -
哈希算法简介与常见的哈希生成算法
2019-11-29 20:15:33哈希(hash)也被称之为散列,是指将任意长度的输入的数据按照某种规则(哈希算法)来变为定长的输出的方式。这个输出也被称之为哈希(散列)值。 哈希表 哈希表(散列表)是一种根据关键码值key来... -
线性代数的本质-01
2020-06-15 21:54:451.从物理专业学生的角度看,向量是空间中的箭头,决定一个向量的是它的长度和它所指的方向,只要以上两个特征相同,你可以自由移动一个向量而保持它不变; 2.从计算机专业学生的视角看,向量是有序的数字列表; 3.从... -
python3的zip()、*zip()、zip(*)的用法 和 zip()在LeetCode中的妙用(未完)
2020-12-25 15:12:29若干个:这些对象的长度有要求么? 没有要求,只要有长度就行,比如a = [1,2,3], b = [1,2,3,4,5],那zip后的元素个数与最短的列表一致。 可迭代的对象 :指的是什么呢? 列表,元组,字典,字符串,这些都可以... -
面试关于Arraylist的底层原理
2021-01-24 17:49:13ArrayList底层原理随机访问与顺序访问ArrayList...随机访问是指在一个长度为n的数组中,想要找到其中第i个元素,只需要知道其下标就行。就那数组举例,为什么数组能实现随机访问呢,从数组内存分析,数组不同于链表,其 -
C++使用SOCKET实现TCP-IP协议的通讯最好的DEMO源码
2019-03-22 16:04:22第一个程序结构负责服务器的启动与客户端连接的登记,首先建立TcpListener网络侦听类,建立的时候构造函数分别包括localaddr和port2个参数,localaddr指的是本地地址,也就是服务器的IP地址,有人会问为什么它自己... -
使用SOCKET实现TCP-IP协议的通讯最好的DEMO源码
2018-05-20 14:44:54第一个程序结构负责服务器的启动与客户端连接的登记,首先建立TcpListener网络侦听类,建立的时候构造函数分别包括localaddr和port2个参数,localaddr指的是本地地址,也就是服务器的IP地址,有人会问为什么它自己... -
你必须知道的495个C语言问题
2015-10-16 14:14:281.4 新的64位机上的64位类型是什么样的? 指针声明 1.5 这样的声明有什么问题?char*p1,p2;我在使用p2的时候报错了。 1.6 我想声明一个指针,并为它分配一些空间,但却不行。这样的代码有什么问题?char*p;*p=... -
几何模型理解线性代数
2018-11-07 21:46:09物理学专特的角度:向量是空间中的箭头,决定一个向量的是它的长度和它指的方向, 是可以随意移动的。 计算机专业学生角度, 向量是有序的数字列表, 例如用向量建模。这里的向量只是列表的另一个表达形... -
《你必须知道的495个C语言问题》
2010-03-20 16:41:181.4 新的64位机上的64位类型是什么样的? 3 指针声明 3 1.5 这样的声明有什么问题?char *p1, p2; 我在使用p2的时候报错了。 3 1.6 我想声明一个指针,并为它分配一些空间,但却不行。这样的代码有什么问题?... -
你必须知道的495个C语言问题(中文高清版)
2013-03-20 13:28:281.4 新的64位机上的64位类型是什么样的? 指针声明 1.5 这样的声明有什么问题?char*p1,p2;我在使用p2的时候报错了。 1.6 我想声明一个指针,并为它分配一些空间,但却不行。这样的代码有什么问题?char*p;*p=... -
[你必须知道的495个C语言问题]人民邮电出版社
2012-08-18 19:02:281.4 新的64位机上的64位类型是什么样的? 指针声明 1.5 这样的声明有什么问题?char*p1,p2;我在使用p2的时候报错了。 1.6 我想声明一个指针,并为它分配一些空间,但却不行。这样的代码有什么问题?char*p;*p=...