我正在使用迭代循环来使用Matplotlib绘制soame数据.当代码保存了大约768个图时,它会抛出以下异常.
RuntimeError: Could not allocate memory for image
Run Code Online (Sandbox Code Playgroud)
我的电脑有大约3.5 GB的RAM.是否有任何方法可以并行释放内存,以免内存耗尽?
如何在此词典列表中仅打印"mid"或"status"?
list = [{'status': 'OK', 'mid': '6269'}, {'status': 'OK', 'mid': '6270'},{'status': 'OK', 'mid': '6271'}, {'status': 'OK', 'mid': '6272'}, {'status': 'OK', 'mid': '6273'}, {'status': 'OK', 'mid': '6274'},{'status': 'OK', 'mid': '6288'}, {'status': 'OK', 'mid': '6289'}]
Run Code Online (Sandbox Code Playgroud)
我尝试过:print list[0]['mid']但它只给出了列表中第一项的'mid'值?我怎么能这样做呢list?
我有以下清单:
[[50.954818803035948, 55.49664787231189, 8007927.0, 0.0],
[50.630482185654436, 55.133473852776916, 8547795.0, 0.0],
[51.32738085400576, 55.118344981379266, 6600841.0, 0.0],
[49.425931642638567, 55.312890225131163, 7400096.0, 0.0],
[48.593467836476407, 55.073137270550006, 6001334.0, 0.0]]
Run Code Online (Sandbox Code Playgroud)
我想打印每个列表中的第三个元素。想要的结果是:
8007927.0
8547795.0
6600841.0
7400096.0
6001334.0
Run Code Online (Sandbox Code Playgroud)
我试过:
print data[:][2]
Run Code Online (Sandbox Code Playgroud)
但它没有输出所需的结果。
我np.random.rand用来创建所需形状的矩阵/张量.但是,此形状参数(在运行时生成)是一个元组,如:(2,3,4).我们如何利用这个shape在np.random.rand?
做np.random.rand(shape)不起作用,会出现以下错误:
TypeError: 'tuple' object cannot be interpreted as an index
是否可以使用for循环在C中获取所有基本数据类型的大小?例如,我们可以这样做吗?
#include <datatypes.h> /* or something else which defines get_data_types() */
#include <stdio.h>
int main() {
for (int x = 0; x < len(get_data_types()); x++) {
printf("Size of %s is %d", get_data_types()[x], sizeof(get_data_types()[x]));
}
}
Run Code Online (Sandbox Code Playgroud)
我可以通过替换for循环并为int,long等编写单独的语句来枚举所有数据类型.但是,我想知道是否有可能有一个for循环来做同样的事情?
基本上,我试图避免以下情况:
#include <stdio.h>
int main() {
printf("Size of int is %d", sizeof(int);
printf("Size of unsigned int is %d", sizeof(unsigned int);
printf("Size of long is %d", sizeof(long);
/* etc. */
return 0;
}
Run Code Online (Sandbox Code Playgroud)
数据类型的兴趣 - ,char,unsigned char, …
python ×4
list ×2
arrays ×1
c ×1
dictionary ×1
matplotlib ×1
numpy ×1
random ×1
sizeof ×1
types ×1