numpy 建立空数组_如何连接一个空数组与Numpy.concatenate?

如果我正确理解你的问题 - 连接不是你正在寻找。连结如你所见:加入along an axis。

如果你想有一个成为另一个值的空矩阵,你可以做到以下几点:

import numpy as np

a = np.zeros([2,2])

b = np.array([[1,2],[3,4]])

my_array = a + b

- 或 -

import numpy as np

my_array = np.zeros([2,2]) # you can use empty here instead in this case.

my_array[0,0] = float(input('Enter first value: ')) # However you get your data to put them into the arrays.

但是,我猜测,是不是你真正想要的,因为你可以使用my_array = b。如果您使用更多信息编辑您的问题,我可能会提供更多帮助。

如果你担心增加随着时间的推移您的数组值...

import numpy as np

a = np.zeros([2,2])

my_array = b # b is some other 2x2 matrix

''' Do stuff '''

new_b # New array has appeared

my_array = new_b # update your array to these new values. values will not add.

# Note: if you make changes to my_array those changes will carry onto new_b. To avoid this at the cost of some memory:

my_array = np.copy(new_b)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值