Ensuring same dimensions in Python

2024/10/5 22:22:14

The dimensions of P is (2,3,3). But the dimensions of M is (3,3). How can I ensure that both P and M have the same dimensions i.e. (2,3,3).

import numpy as np
P=np.array([[[128.22918457, 168.52413295, 209.72343319],[129.01598287, 179.03716051, 150.68633749],[131.00688309, 187.42601593, 193.68172751]],[[ 64.11459228,  84.26206648, 104.86171659],[ 64.50799144,  89.51858026,  75.34316875],[ 65.50344155,  93.71300796,  96.84086375]]])for x in range(0,2):M=P[x]+1print(M)
Answer

Just do

M = P + 1

and that ensures M and P have the same dimensions.

https://en.xdnf.cn/q/119734.html

Related Q&A

how to stop tkinter timer function when i press button one more times?

id tried to use root.after_cancel(AFTER), but i dont know how.root.after_cancel(AFTER) AFTER = None def countdown(count,time,name):global AFTERtime[text] =name,":",datetime.fromtimestamp(cou…

Read csv into database SQLite3 ODO Python

I am trying to read in a csv into a new table in a new databased using ODO, SQLite3 and Python.I am following these guides:https://media.readthedocs.org/pdf/odo/latest/odo.pdf http://odo.pydata.org/en/…

netmiko cant execute sh run | i host

I notice that my netmiko code cant run sh run | i host which is a legitimate Cisco command.When I replace sh run with other command such as sh clo, or show ip interface brief, it works perfectly.from n…

How to dump the data from file to an excel sheet

I want to dump [3-4 lines together] some data to an excel sheet. I could able to dump single line based on some criteria [like if line is getting start with // or /* ], but in case of when lines starts…

I dont understand why my script is not iterating through all string.split elements?

The objective of this python exercise is to build a function that turns text into pig latin, a simple text transformation that modifies each word by moving the first character to the end and appending …

Unable to change the tick frequency on my chart

I have seen many questions on changing the tick frequency on SO, and that did help when I am building a line chart, but I have been struggling when its a bar chart. So below are my codes import numpy a…

Django Queryset foreign keys

I am trying to get a queryset but it is not displaying anything. Basically, I want to get the Asset objects that are assigned via foreign key to an employee, which is a foreign key of the signed in use…

How to reorder the columns of a CSV?

How can I re-order the columns of a CSV file using Python? These are the first rows of a CSV file I need to change:03;30269714;Ramiro Alberto;Nederz;active;pgc_gral 03;36185520;Andrea;Espare;active;pg…

Distance matrix in Python Pandas

I am a newbie in python, but I like to process data in pandas. I have a hundred pairs of CSV data such as passenger and bus stop data. The passenger structure data is Person, and XY coordinates (UTM-Me…

calculating catalan numbers using memoization

I am tring to use memoization in order to calculate catalan numbers, but it just does not seem to work, what do I need to change?def catalan_mem(n, memo = None):if n==0:return 1if memo == None:memo = …