python如何将数组里的数提取出来_python – 如何从numpy数组中提取任意值的值?...

@ Sven的答案是简单的方法,但对于大型数组来说效率很低。如果你处理的是一个相对较小的数组,你不会注意到差别,如果你想要从一个大(例如> 50 MB)的配置文件,你可能想尝试一些其他的方法。你需要使用“像素”坐标为这些,所以有一个额外的复杂性。

还有两种内存高效的方法。 1)如果需要双线性或三次插值,使用scipy.ndimage.map_coordinates。 2)如果你只是想要最近邻居采样,那么只是直接使用索引。

作为第一个例子:

import numpy as np

import scipy.ndimage

import matplotlib.pyplot as plt

#-- Generate some data...

x, y = np.mgrid[-5:5:0.1, -5:5:0.1]

z = np.sqrt(x**2 + y**2) + np.sin(x**2 + y**2)

#-- Extract the line...

# Make a line with "num" points...

x0, y0 = 5, 4.5 # These are in _pixel_ coordinates!!

x1, y1 = 60, 75

num = 1000

x, y = np.linspace(x0, x1, num), np.linspace(y0, y1, num)

# Extract the values along the line, using cubic interpolation

zi = scipy.ndimage.map_coordinates(z, np.vstack

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值