Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

what does .shape do in python

#The shape attribute for numpy arrays returns the dimensions of the array. 
#If Y has n rows and m columns, then Y. shape is (n,m) .
import numpy as np
arr= np.array([[6, 1, 2, 1],
               [5, 4, 6, 7,],
               [6, 7, 2, 1,]])
result = np.shape(arr)
print(result)
#will return (3,4)
Comment

Python NumPy Shape function syntax

numpy.shape(array_name)
Comment

shape of variable python

variable.shape()
Comment

shape function python

# Example from https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html
y = np.zeros((2, 3, 4))
y.shape # this returns (2, 3, 4)
Comment

shape in python

If you want to draw a shape download/install a GUI Library for Python like Pygame

import pygame as pg #Optional, just write: import pygame



#Draw a rectangle: pg.draw.rect(surface, (r, g, b), pg.Rect(x, y, width, height)

#Draw a circle: pg.draw.circle(surface, (r, g, b), (x, y), radius)

#Draw a line: pg.draw.circle(surface, (r, g, b), (x1, y1), (x2, y2), width))

#Draw a custom shape: pg.draw.polygon(surface, (r, g, b), points, width) #points is a list of
#points like: points = [(x1, y1), (x2, y2), (x3, y3)... (xn, yn)]

#Draw an ellipse: pg.draw.ellipse(surface, (r, g, b), pg.Rect(x, y, width, height))
#The rectangle is just for the location and dimensions of the ellipse

#Draw an arc: pg.draw.arc(surface, (r, g, b), pg.Rect(x, y, width, height), start_angle, stop_angle)
#The rect is for dimensions and location of the arc

#There is also anti-aliased (aa) shapes which I wont get into but it means the shapes will
#be 'smoother'.

Comment

PREVIOUS NEXT
Code Example
Python :: calculator python tutorial 
Python :: reference variable python 
Python :: pygame draw square 
Python :: shape in python 
Python :: python __new__ 
Python :: fastest way to check odd or even in python 
Python :: how to remove trailing zeros in python 
Python :: pytest-mock tutorial 
Python :: python elif syntax 
Python :: django filter on related field 
Python :: pandas change column order 
Python :: find last element in list python 
Python :: how to add one to the index of a list 
Python :: how to sum only the odd values in python 
Python :: calculate iqr in python dataset example 
Python :: open chrome console in selenium 
Python :: add Elements to Python list Using insert() method 
Python :: extract text from image python without tesseract 
Python :: how to move an item from one list to another python 
Python :: timeit command line 
Python :: pandas qcut 
Python :: how to create a variable that represents any integer in python 
Python :: python excel sheet 
Python :: group normalization 
Python :: exchange sort python 
Python :: code error correction 
Python :: pysolr - connect to solr via vpn 
Python :: sys executable juypter is incorrect visual code 
Shell :: error: cannot install "code": classic confinement requires snaps under /snap or symlink from /snap 
Shell :: Please install the gcc make perl packages from your distribution. 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =