python中怎樣使用shape計算矩陣的行和列

2021-03-03 20:27:50 字數 4085 閱讀 6800

1樓:匿名使用者

>>> import numpy as np

>>> a = np.arange(1,11).reshape(10,1)

>>> b = a * 1.1

>>> c = a / 1.1

>>> a

array([[ 1],

[ 2],

[ 3],

[ 4],

[ 5],

[ 6],

[ 7],

[ 8],

[ 9],

[10]])

>>> b

array([[ 1.1],

[ 2.2],

[ 3.3],

[ 4.4],

[ 5.5],

[ 6.6],

[ 7.7],

[ 8.8],

[ 9.9],

[ 11. ]])

>>> c

array([[ 0.90909091],

[ 1.81818182],

[ 2.72727273],

[ 3.63636364],

[ 4.54545455],

[ 5.45454545],

[ 6.36363636],

[ 7.27272727],

[ 8.18181818],

[ 9.09090909]])

>>> x = np.array([

... np.reshape(a, len(a)),

... np.reshape(b, len(b)),

... np.reshape(c, len(c))

... ]).transpose()

>>> x

array([[ 1. , 1.1 , 0.90909091],

[ 2. , 2.2 , 1.81818182],

[ 3. , 3.3 , 2.72727273],

[ 4. , 4.4 , 3.63636364],

[ 5. , 5.5 , 4.54545455],

[ 6. , 6.6 , 5.45454545],

[ 7. , 7.7 , 6.36363636],

[ 8. , 8.8 , 7.27272727],

[ 9. , 9.9 , 8.18181818],

[ 10. , 11. , 9.09090909]])

>>>

python中怎樣使用shape計算矩陣的行和列

2樓:日time寸

import numpy

a = numpy.array([[1,2,3],[4,5,6]])print a.shape

矩陣有一個shape屬性,是一個(行,列)形式的元組

python中怎樣使用shape計算矩陣的行和列

3樓:匿名使用者

import numpy

a = numpy.array([[1,2,3],[4,5,6]])print a.shape

矩陣有一個shape屬性,是一個(行,列)形式的元組

4樓:匿名使用者

你得先安裝numpy庫,矩陣

(ndarray)的shape屬性可以獲取矩陣的形狀(例如二維陣列的行專列),獲取的結果是一屬個元組,因此相關**如下:

import numpy as np

x = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]])

# 輸出陣列的行和列數

print x.shape # (4, 3)# 只輸出行數

print x.shape[0] # 4

# 只輸出列數

print x.shape[1] # 3

python中怎樣使用shape計算矩陣的行和列

5樓:匿名使用者

屬於numpy庫的方源法

import numpy

a=numpy.zeros((5,5),dtype='int32')a.shape

輸出為(5,5) 可以用

a.shape[0]

看行數bai(也就是

du第一個維度)

p.s. 可以初始zhi化高維矩陣dao 就是a可以不止二維

python中怎樣使用shape計算矩陣的行和列

6樓:碧血玉葉花

>>> import numpy as np

>>> a = np.arange(1,11).reshape(10,1)

>>> b = a * 1.1

>>> c = a / 1.1

>>> a

array([[ 1],

[ 2],

[ 3],

[ 4],

[ 5],

[ 6],

[ 7],

[ 8],

[ 9],

[10]])

>>> b

array([[ 1.1],

[ 2.2],

[ 3.3],

[ 4.4],

[ 5.5],

[ 6.6],

[ 7.7],

[ 8.8],

[ 9.9],

[ 11. ]])

>>> c

array([[ 0.90909091],

[ 1.81818182],

[ 2.72727273],

[ 3.63636364],

[ 4.54545455],

[ 5.45454545],

[ 6.36363636],

[ 7.27272727],

[ 8.18181818],

[ 9.09090909]])

>>> x = np.array([

... np.reshape(a, len(a)),

... np.reshape(b, len(b)),

... np.reshape(c, len(c))

... ]).transpose()

>>> x

array([[ 1. , 1.1 , 0.90909091],

[ 2. , 2.2 , 1.81818182],

[ 3. , 3.3 , 2.72727273],

[ 4. , 4.4 , 3.63636364],

[ 5. , 5.5 , 4.54545455],

[ 6. , 6.6 , 5.45454545],

[ 7. , 7.7 , 6.36363636],

[ 8. , 8.8 , 7.27272727],

[ 9. , 9.9 , 8.18181818],

[ 10. , 11. , 9.09090909]])

>>>

python中怎樣使用shape計算矩陣的行和列

7樓:依蘭彬歌

import numpy

a = numpy.array([[1,2,3],[4,5,6]])print a.shape

矩陣有一個shape屬性,是一個(行,列)形式的元組

怎樣使用python訪問mongodb

安裝驅復動pymongo 輸入命令 制pip install pymongo 直接使用驅動 orm框架 flask mongoengine 輸入命令 pip install flask mongoengine 使用介紹 建立連線 切換資料庫 獲取collection db和collection都是延...

使用python中的for迴圈和if條件使一組資料按升序排列,最簡單的

不過不用 抄for和if,最簡單襲的是sort方法,list.sort 用的話可以用氣泡排序演算法 def bubble l for i in range len l for j in range len l 1 if l j l j 1 l j l j 1 l j 1 l j return l p...

CF中雷達怎樣使用

看你是使用大的還那個小的,大的話你是看人在 或人在 死的,這樣你可以初步判斷敵人在哪個方向,小雷達也是同樣的道理。給我採納為答案吧。按lnsert就可以了 顯示隊友名字的 按delete是雷達顯示 穿越火線怎樣看雷達,怎樣看敵人在 可以通過隊友的報點和螢幕左上角的小雷達來判斷敵人的大致位置,然後靜步...