我需要从Python转换到C/C++。你知道有没有快速的“参考教程”或类似于Numpy和Scipy教程的东西可以作为起点参考吗?我已经阅读了很多“文档”,例如:
感谢您提供的任何建议!:)
- C++ for dummies
- the K&R C Programming Language
- 许多博客和在线文档,如:http://eli.thegreenplace.net/2010/01/11/pointers-to-arrays-in-c/,
- http://newdata.box.sk/bx/c/
- 大量的StackOverflow问答
- ...
#!/usr/bin/env python
import time
import numpy as np
import tables as tb
"""Retrieve 3D positions form 1000 files and store them in one single HDF5 file.
"""
t = time.time()
# Empty array
sample = np.array([])
sample.shape = (0,3)
# Loop over the files
for i in range(0, 1000):
filename = "mill2sort-"+str(i)+"-extracted.h5"
print "Doing ", filename
# Open data file
h5f = tb.openFile(filename, 'r')
# Stack new data under previous data
sample = np.vstack((sample, h5f.root.data.read()))
h5f.close()
# Create the new file
h5 = tb.openFile("mill2sort-extracted-all", 'w')
# Save the array
h5.createArray(h5.root, 'data', sample, title='mill_2_sub_sample_all')
h5.flush()
h5.close()
print "Done in ", time.time()-t, " seconds."
在C或C++中,例如我甚至不知道如何将一个3D数组传递给一个函数以找到它的维度,类似于
int getArrayDimensions(int* array, int *dimensions){
*dimensions = sizeof(*array)/sizeof(array[0]);
return 0;
}
使用数组时,
int array[3][3][3] = ...
感谢您提供的任何建议!:)