Questions tagged «arrays»

数组是一种有序的数据结构,由一组元素(值,变量或引用)组成,每个元素由一个或多个索引标识。当询问数组的特定变体时,请使用以下相关标记:[vector],[arraylist],[matrix]。使用此标签时,在特定于编程语言的问题中,使用正在使用的编程语言对问题进行标签。

4
在结构数组的末尾需要空括号'{}'是什么?
我在Linux内核中命中了一些C 代码: static struct ctl_table ip_ct_sysctl_table[] = { { .procname = "ip_conntrack_max", .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec, }, // ... { .procname = "ip_conntrack_log_invalid", .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = &log_invalid_proto_min, .extra2 = &log_invalid_proto_max, }, { } }; 这里的结构数组以结尾{ }。它是出于什么目的添加的? …

8
按降序对数字进行排序,但开头应为0
我在JavaScript中遇到了一个挑战,已经尝试了一段时间。 考虑以下数组: let arr = [0, 1, 0, 2, 0, 3, 0, 4, 0, 5]; 我必须输出以下结果: arr = [0, 0, 0, 0, 0, 5, 4, 3, 2, 1] 我遵循以下逻辑行将零放置在前面,从而调整索引值: arr.sort((x, y) => { if (x !== 0) { return 1; } if (x === 0) { return -1; } return …

12
如何从数组创建数组
已关闭。这个问题需要更加集中。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过编辑此帖子来关注一个问题。 上个月关闭。 我是一名JavaScript初学者,我尝试使用一个主数组中的值制作两个不同的数组。 我的主数组如下: 0: Array(3) [ 2011, 127072.7, 51584 ] 1: Array(3) [ 2012, 125920.3, 59974 ] 2: Array(3) [ 2013, 129305.4, 15468 ] 3: Array(3) [ 2014, 135364, 84554 ] 4: Array(3) [ 2015, 136757, 98754 ] 5: Array(3) [ 2016, 155653.5, 155548 ] 6: Array(3) [ …

8
numpy 1D数组:遮罩元素重复n次以上
给定整数数组 [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5] 我需要掩盖重复N多次的元素。需要说明的是:主要目标是检索布尔掩码数组,以后再用于装箱计算。 我想出了一个相当复杂的解决方案 import numpy as np bins = np.array([1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) N = 3 …
18 python  arrays  numpy  binning 

3
static int arr [10]存储器地址始终以060结尾
我有一个看起来像这样的交流程序 main.c #include <stdio.h> #define SOME_VAR 10 static int heap[SOME_VAR]; int main(void) { printf("%p", heap); return 0; } 并在运行编译程序几次后输出 0x58aa7c49060 0x56555644060 0x2f8d1f8e060 0x92f58280060 0x59551c53060 0xd474ed6e060 0x767c4561060 0xf515aeda060 0xbe62367e060 为什么总是以060结尾?数组是否存储在堆中? 编辑:我在Linux上,并且我有ASLR。我用gcc编译了程序
17 c  arrays  memory 

4
将javascript中的数组更改为更简单的对象
我有一个简单的JSON,数组中包含其他对象等,如下所示: languagePack: [ { 'key': 'Username', 'value': 'Benutzername', 'group': 'default' }, { 'key': 'Password', 'value': 'Passwort', 'group': 'default' } ] 但是我真正想要的是这样的对象: languagePack: { 'Username': 'Benutzername', 'Password': 'Passwort' } 因此,我想将数组简化为数组甚至对象内部的简单键值对(键是唯一的)。有谁知道如何通过一些很棒的数组函数来减少这种情况?我只为每个对象想出了一个类似的东西,并为属性建立了“手工”对象的属性,但我记得数组中有一些很棒的东西,例如“ reduce”,散布运算符(...),map,一些,等等 我尝试了类似的东西: var temp = this.languagePack.map(([key, value]) => ({key,value})) console.log(temp) 但这只会给我一条错误消息 TypeError: Invalid attempt to destructure non-iterable instance 编辑:所有三个答案都工作正常。谢谢。

7
JavaScript数组重组
我有一个包含学生和家长地址的数组。 例如, const users = [{ id: 1, name: 'John', email: 'johnson@mail.com', age: 25, parent_address: 'USA', relationship:'mother' }, { id: 1, name: 'John', email: 'johnson@mail.com', age: 25, parent_address: 'Spain', relationship:'father' }, { id: 2, name: 'Mark', email: 'mark@mail.com', age: 28, parent_address: 'France', relationship:'father' } ]; 我正在尝试将其重新格式化为以下结果。 const list = [ …


1
为什么np.dot不精确?(n维数组)
假设我们采用np.dot两个'float32'2D数组: res = np.dot(a, b) # see CASE 1 print(list(res[0])) # list shows more digits [-0.90448684, -1.1708503, 0.907136, 3.5594249, 1.1374011, -1.3826287] 数字。除了它们可以更改: 案例1:切片a np.random.seed(1) a = np.random.randn(9, 6).astype('float32') b = np.random.randn(6, 6).astype('float32') for i in range(1, len(a)): print(list(np.dot(a[:i], b)[0])) # full shape: (i, 6) [-0.9044868, -1.1708502, 0.90713596, 3.5594249, 1.1374012, -1.3826287] …
15 python  c  arrays  numpy  precision 

2
向量作为键在C ++内部如何工作?
该SO回答说,带有向量作为密钥的STL映射,该向量可用作密钥。因此,当我们使用向量作为键时。由于键需要唯一,因此该键实际如何工作,因此当我们插入具有相同元素的另一个向量时,将map检查逐个元素重复还是向量名称确实指定了某些东西?就像数组的名称代表基地址一样。因此,可以将数组用作键,因为在这种情况下基地址可以用作键,但是在向量的情况下,键是什么。它是如何在内部工作的。 因为当我打印矢量的名称时,我确实得到了一个错误 vector<int> v; cout<<v; //error
14 c++  arrays  dictionary  vector  stl 

5
过滤后将阵列合并到一个阵列
我有对象数组,我只用位置数组。我的目标是将这些locations数组合并为一个数组,但是我这样做并没有得到空数组。这是我的方法: let results = [{ id: '1', locations: ['aaaa', 'bbbbbb', 'cccccc'] }, { id: '2', locations: [] }, { id: '3', locations: ['ddd', 'aaadsad', 'sefd'] }, { id: '4', locations: ['ffff', 'eeee', 'sfdsfsd'] }, ]; const locationIds = [].concat.apply([], ...results.filter(s => s.locations && s.locations.length > 0).map(({ locations }) => ({ …

2
我想将新的segmentId(具有相同的名称)添加到映射数组中,但具有不同的elementId但具有相同的方法
以下是MapperInterface.php 我试图弄清楚如何在const中添加if-else语句。映射数组。像这样: if (LIN02 == “VN”) o Treat LIN03 as the SKU · else if (LIN04 == “VN”) o Treat LIN05 as the SKU <?php declare(strict_types=1); namespace Direct\OrderUpdate\Api; use Direct\OrderUpdate\Api\OrderUpdateInterface; /** * Interface MapperInterface * Translates parsed edi file data to a \Direct\OrderUpdate\Api\OrderUpdateInterface * @package Direct\OrderUpdate\Api */ interface MapperInterface { …
14 php  arrays  mapping  const 

3
为什么数组的维是其类型的一部分?
在阅读C ++ Primer书籍时,我遇到了这样的说法:“数组中元素的数量是数组类型的一部分。” 因此,我想使用以下代码进行查找: #include<iostream> int main() { char Array1[]{'H', 'e', 'l', 'p'}; char Array2[]{'P', 'l', 'e', 'a', 's', 'e'}; std::cout<<typeid(Array1).name()<<std::endl; //prints A4_c std::cout<<typeid(Array2).name()<<std::endl; //prints A6_c return 0; } 有趣的是,两个数组上的typeid结果表明它们有所不同。 幕后发生了什么事? 为什么数组必须具有包含其大小的类型?仅仅是因为它的大小不应该改变吗? 这将如何影响比较数组? 只是希望能够深刻理解这个概念。
14 c++  arrays  c++11 

1
1 MB或更大的Java字节数组占用RAM的两倍
在Windows 10 / OpenJDK 11.0.4_x64上运行下面的代码会作为输出used: 197和输出expected usage: 200。这意味着200个字节数组(一百万个元素)占用了大约。200MB RAM。一切都很好。 当我将代码中的字节数组分配从new byte[1000000]更改为new byte[1048576](即更改为1024 * 1024个元素)时,它会作为输出used: 417和产生expected usage: 200。有没有搞错? import java.io.IOException; import java.util.ArrayList; public class Mem { private static Runtime rt = Runtime.getRuntime(); private static long free() { return rt.maxMemory() - rt.totalMemory() + rt.freeMemory(); } public static void main(String[] args) throws InterruptedException, …

2
如何理解此Java 8 Stream collect()方法?
我试图将一个int数组转换为List,并且采取了使用Java 8 Stream的陌生路线,并提出了这个建议。 Arrays.stream(arr).boxed().collect(Collectors.toList()); 我仍然很难完全理解这条线, 为什么Collectors.toList()在这种情况下返回一个ArrayList<Integer>实现List接口?为什么不LinkedList<Integer>符合List接口的通用类呢?我找不到这事,除了简短提的ArrayList 这里,在API说明部分。 左边的 意思是什么?显然是通用返回类型(在我的代码中)。而且我认为是该方法的泛型类型参数,但是如何指定它们呢?我查看了Collector界面文档,但无法吸收它。 Stream.collect()RArrayList<Integer><R, A>

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.