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

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 :: python hide input 
Python :: show columns pandas 
Python :: how to unpivot dataframe pandas 
Python :: calculate distance in python 
Python :: how to convert into grayscale opencv 
Python :: qtablewidget not editable python 
Python :: flask subdomains 
Python :: selenium open inspect 
Python :: append dataframe pandas 
Python :: def function python 
Python :: sys.path.append python 
Python :: compare two dictionaries in python 
Python :: numpy save multiple arrays 
Python :: linked lists python 
Python :: python user input 
Python :: python int to binary string 
Python :: how to add window background in pyqt5 
Python :: get the last element from the list 
Python :: python lambda 
Python :: pandas df to mongodb 
Python :: fork function in python 
Python :: How to loop over grouped Pandas dataframe? 
Python :: get query param in django 
Python :: matplotlib log scale y axis base 
Python :: create virtual environments python 
Python :: generate dates between two dates python 
Python :: how to add phone number to django user model 
Python :: get the name of a current script in python 
Python :: show all rows for dataframe 
Python :: stack queue in python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =