相关疑难解决方法(0)

numpy:用索引数组有效求和

假设我有2个矩阵M和N(都有> 1列).我还有一个索引矩阵I,有2列 - 1表示M,1表示N.N的索引是唯一的,但M的索引可能出现不止一次.我想要执行的操作是,

for i,j in w:
  M[i] += N[j]
Run Code Online (Sandbox Code Playgroud)

除了for循环之外,还有更有效的方法吗?

python numpy

10
推荐指数
1
解决办法
311
查看次数

在每个HealPix像素的中心写一个数字

我有一个用HEALPY制作的HealPix图,如Healpy:从数据到Healpix图(像素较少,例如,nside = 2,请参见下面的代码)。

import healpy as hp
import numpy as np
import matplotlib.pyplot as plt

# Set the number of sources and the coordinates for the input
nsources = int(1.e4)
nside = 2
npix = hp.nside2npix(nside)

# Coordinates and the density field f
thetas = np.random.random(nsources) * np.pi
phis = np.random.random(nsources) * np.pi * 2.
fs = np.random.randn(nsources)

# Go from HEALPix coordinates to indices
indices = hp.ang2pix(nside, thetas, phis)

# Initate the map and fill it …
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib healpy

6
推荐指数
0
解决办法
102
查看次数

标签 统计

python ×2

healpy ×1

matplotlib ×1

numpy ×1

plot ×1