如何获取ndarray中索引以外的其它所有值

方法一:

import numpy as np
a = np.array([0,1,2,3,4,5,5,6,7,8,9])
print(a)
print(a.sum())
# [0 1 2 3 4 5 5 6 7 8 9]
# 50
a = np.ma.array(a, mask=False)
a.mask[3] = True
print(a)
print(a.sum())
# [0 1 2 -- 4 5 5 6 7 8 9]
# 47
方法二
a_new = np.delete(a, 3, 0)
这个3可以是个索引列表

C字符串

想把一列台站名输出成一行,用空格隔开,写了个C。

fgets(buff,1024,fp);
strncpy(temp,buff,strlen(buff)-1);
printf('%s ',temp);

发现当台站名由长变短时,会“继承”上一个台站的后面几个字符,比如前一个台站名为L5317,而后一个为Y02时,前一个正确,而后一个会变成Y0217.怀疑是temp保存了上一次的’\0’的位置,所以在每次printf后强行temp[0]=’\0’,发现没用,考虑是上次的字符串终止符还在。
我试了以下几种方法,都行:

1 每次printf后,temp[strlen(a)-1]=’0’;

2 用malloc给temp分配内存,读到了新的,就realloc一次,记得最后free掉;   temp=(char *)realloc(temp,sizeof(char)*(strlen(buff)-1))

3 直接把buff数组的最后一个值换成’\0’,然后输出buff。 buff[strlen(buff)-1]=’\0′

pandas中的parse_dates以及绘图

某列中的数据要能被完整parse为时间值,可以用dateutil.parse中的parse来测试一下,不足的位数要补齐。比如一个文件temp.txt包含两列数,一列时间,一列观测数据200101011001 -3.9

import pandas as pd

import matplotlib.pyplot as plt

dat=pd.read_csv(‘temp.txt’,head=0,sep=’\s+’,names=[‘time’,’values’],parse_dates=[‘time’])
dat.plot(x=’time’,y=’values’)

plt.show()

macOS安装X11

https://support.apple.com/zh-cn/HT201341

Mac 不再随附 X11,但 XQuartz 项目会提供 X11 服务器和客户端库。

Apple 创建了 XQuartz 项目,共同致力于在 Mac 上进一步开发和支持 X11。XQuartz 项目最初基于 Mac OS X v10.5 中随附的 X11 版本。目前有多个版本的 XQuartz,其中包含修复程序、针对新功能的支持以及 X11 体验的更多改进功能。Apple 是 XQuartz 项目的贡献者,并致力于确保 X11 与 macOS 和最新版本的 XQuartz 正常配合使用。 

XQuartz 项目提供适用于 MacOS 的 X11 服务器和客户端库,网址是 www.xquartz.org。下载可用的最新版本。

////////////////////////////////////////////////////////////////////////////////////////////

专业软件用到了x11,但编译的时候报错说是没有x11,按照以上通知,安装了XQuartz后,程序运行正常。

brew install xquartz

heapsort快速排序

void sort(float arr[], unsigned int N)
  { // heapsort algorithm
      unsigned int n = N, i = n/2, parent, child;
      int t;

      for (;;) { /* Loops until arr is sorted */
          if (i > 0) { /* First stage - Sorting the heap */
              i--;           /* Save its index to i */
              t = arr[i];    /* Save parent value to t */
          } else {     /* Second stage - Extracting elements in-place */
              n--;           /* Make the new heap smaller */
              if (n == 0) return; /* When the heap is empty, we are done */
              t = arr[n];    /* Save last value (it will be overwritten) */
              arr[n] = arr[0]; /* Save largest value at the end of arr */
          }

          parent = i; /* We will start pushing down t from parent */
          child = i*2 + 1; /* parent's left child */

          /* Sift operation - pushing the value of t down the heap */
          while (child < n) {
              if (child + 1 < n  &&  arr[child + 1] > arr[child]) {
                  child++; /* Choose the largest child */
              }
              if (arr[child] > t) { /* If any child is bigger than the parent */
                  arr[parent] = arr[child]; /* Move the largest child up */
                  parent = child; /* Move parent pointer to this child */
                  //child = parent*2-1; /* Find the next child */
                  child = parent*2+1; /* the previous line is wrong*/
              } else {
                  break; /* t's place is found */
              }
          }
          arr[parent] = t; /* We save t in the heap */
      }
  }